Skip to content

Commit

Permalink
Fixed the server select bug by removing the back option.
Browse files Browse the repository at this point in the history
implemented an algorithm to sort the header items.

Fixed the spinner bug.

Removed the back button from connection selector.
  • Loading branch information
octacode committed Jul 11, 2017
1 parent 0d95757 commit 7a47eb0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedIns

setCheckedActionButtons(actions);

setBackButton(actions);
}

private void setTitle(List<GuidedAction> actions) {
Expand Down Expand Up @@ -165,18 +164,6 @@ private void addCheckedAction(List<GuidedAction> actions, int iconResId, Context
actions.add(guidedAction);
}

private void setBackButton(List<GuidedAction> actions) {
addAction(actions, ACTION_BACK, getString(R.string.pref_option_go_back), "");
}

private void addAction(List<GuidedAction> actions, long id, String title, String desc) {
actions.add(new GuidedAction.Builder(mContext)
.id(id)
.title(title)
.description(desc)
.build());
}

@Override
public void onGuidedActionClicked(GuidedAction action) {

Expand All @@ -192,11 +179,14 @@ public void onGuidedActionClicked(GuidedAction action) {
if (OPTION_NAMES.get(getSelectedActionPosition() - 1).matches(getString(R.string.preference_entry_server_connection_local))) {
Preferences.setPrefLocal(preference, mContext);
}
} else {
if (initialSelected.matches(Preferences.getServerConnection(preference, mContext)))
getActivity().finish();
else
startActivity(new Intent(getActivity(), NavigationActivity.class));
keepCheck();
}
}

private void keepCheck() {
if (initialSelected.matches(Preferences.getServerConnection(preference, mContext)))
getActivity().finish();
else
startActivity(new Intent(getActivity(), NavigationActivity.class));
}
}
17 changes: 17 additions & 0 deletions src/main/java/org/amahi/anywhere/tv/fragment/MainTVFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,14 @@ public void onFilesLoaded(ServerFilesLoadedEvent event) {
}
}
}

if (listRow != null) {
int index1 = mRowsAdapter.indexOf(listRow);
int index2 = mRowsAdapter.indexOf(settingsRow);
mRowsAdapter.replace(index1, settingsRow);
mRowsAdapter.replace(index2, listRow);
}
sortHeaders();
setAdapter(mRowsAdapter);
}

Expand All @@ -185,6 +187,21 @@ private void addSettings(ArrayObjectAdapter adapter) {
adapter.add(0, settingsRow);
}

private void sortHeaders(){
for(int i=0;i<mRowsAdapter.size()-1;i++){
for(int j=i+1;j<mRowsAdapter.size()-1;j++){
ListRow listRow1 = (ListRow)mRowsAdapter.get(i);
ListRow listRow2 = (ListRow)mRowsAdapter.get(j);
if((int)listRow2.getHeaderItem().getName().charAt(0)<(int)listRow1.getHeaderItem().getName().charAt(0)){
int index1 = mRowsAdapter.indexOf(listRow1);
int index2 = mRowsAdapter.indexOf(listRow2);
mRowsAdapter.replace(index1, listRow2);
mRowsAdapter.replace(index2, listRow1);
}
}
}
}

private List<ServerFile> sortFiles(List<ServerFile> files) {
List<ServerFile> sortedFiles = new ArrayList<ServerFile>(files);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.support.v17.leanback.widget.GuidanceStylist;
import android.support.v17.leanback.widget.GuidedAction;
import android.support.v4.content.ContextCompat;
import android.widget.Toast;

import org.amahi.anywhere.R;
import org.amahi.anywhere.activity.NavigationActivity;
Expand All @@ -42,7 +43,7 @@
public class ServerSelectFragment extends GuidedStepFragment {

private static final int OPTION_CHECK_SET_ID = 10;
private static final int ACTION_BACK = 0;
private int indexSelected = 0;
private Context mContext;
private ArrayList<Server> mServerArrayList;
private ArrayList<String> OPTION_NAMES = new ArrayList<>();
Expand Down Expand Up @@ -84,7 +85,6 @@ public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedIns
if (serverName == null) {
setDefaultChecked();
} else {
int indexSelected = 0;
for (int i = 0; i < mServerArrayList.size(); i++) {
if (serverName.matches(mServerArrayList.get(i).getName())) {
indexSelected = i;
Expand All @@ -96,7 +96,6 @@ public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedIns
}

setCheckedActionButtons(actions);
setBackButton(actions);
}

private void setTitle(List<GuidedAction> actions) {
Expand Down Expand Up @@ -179,25 +178,16 @@ private void addCheckedAction(List<GuidedAction> actions, int iconResId, Context
actions.add(guidedAction);
}

private void setBackButton(List<GuidedAction> actions) {
addAction(actions, ACTION_BACK, getString(R.string.pref_option_go_back), "");
}

private void addAction(List<GuidedAction> actions, long id, String title, String desc) {
actions.add(new GuidedAction.Builder(mContext)
.id(id)
.title(title)
.description(desc)
.build());
}

@Override
public void onGuidedActionClicked(GuidedAction action) {
if (getSelectedActionPosition() <= mServerArrayList.size()) {
String server = mServerArrayList.get(getSelectedActionPosition() - 1).getName();
Preferences.setServertoPref(server, mContext, mSharedPref);
} else {
startActivity(new Intent(mContext, NavigationActivity.class));
if (indexSelected == (getSelectedActionPosition() - 1))
getActivity().finish();
else {
Preferences.setServertoPref(server, mContext, mSharedPref);
startActivity(new Intent(mContext, NavigationActivity.class));
}
}
}
}

0 comments on commit 7a47eb0

Please sign in to comment.