Change radio with spinners

This commit is contained in:
tom79 2019-09-25 19:08:47 +02:00
parent 43f62f7b9a
commit 4b919037e1
3 changed files with 110 additions and 118 deletions

View File

@ -35,8 +35,6 @@ import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import app.fedilab.android.R; import app.fedilab.android.R;
import app.fedilab.android.fragments.ContentSettingsFragment; import app.fedilab.android.fragments.ContentSettingsFragment;
import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.Helper;
@ -145,8 +143,6 @@ public class SettingsActivity extends BaseActivity {
} }
private class SettingsPagerAdapter extends FragmentStatePagerAdapter { private class SettingsPagerAdapter extends FragmentStatePagerAdapter {
SettingsPagerAdapter(FragmentManager fm) { SettingsPagerAdapter(FragmentManager fm) {
@ -197,9 +193,6 @@ public class SettingsActivity extends BaseActivity {
} }
} }
public void setActionBarTitle(String title) {
Objects.requireNonNull(getSupportActionBar()).setTitle(title);
}
@Override @Override
public void onDestroy() { public void onDestroy() {

View File

@ -125,6 +125,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
private type type; private type type;
private Context context; private Context context;
private AsyncTask asyncTask;
@Override @Override
public void onRetrieveRemoteAccount(Results results) { public void onRetrieveRemoteAccount(Results results) {
@ -142,7 +143,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
translatorManager.notifyDataSetChanged(); translatorManager.notifyDataSetChanged();
break; break;
} }
new RetrieveRelationshipAsyncTask(context, account.getId(), ContentSettingsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); asyncTask = new RetrieveRelationshipAsyncTask(context, account.getId(), ContentSettingsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
} }
@ -181,6 +182,8 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
private static final int ACTIVITY_CHOOSE_SOUND = 412; private static final int ACTIVITY_CHOOSE_SOUND = 412;
int count6 = 0; int count6 = 0;
int count7 = 0; int count7 = 0;
int count8 = 0;
int count9 = 0;
private int style; private int style;
public static ContentSettingsFragment newInstance(int resId) { public static ContentSettingsFragment newInstance(int resId) {
@ -414,44 +417,57 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
new DownloadTrackingDomainsAsyncTask(getActivity().getApplicationContext(), update_tracking_domains).execute(); new DownloadTrackingDomainsAsyncTask(getActivity().getApplicationContext(), update_tracking_domains).execute();
}); });
//Manage download of attachments
RadioGroup radioGroup = rootView.findViewById(R.id.set_attachment_group); Spinner set_attachment_group = rootView.findViewById(R.id.set_attachment_group);
String[] attachment_labels = {context.getString(R.string.set_attachment_always), context.getString(R.string.set_attachment_wifi), context.getString(R.string.set_attachment_ask)};
ArrayAdapter<String> adapterAttachment = new ArrayAdapter<>(context,
android.R.layout.simple_spinner_dropdown_item,attachment_labels );
set_attachment_group.setAdapter(adapterAttachment);
int attachmentAction = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); int attachmentAction = sharedpreferences.getInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
switch (attachmentAction) { switch (attachmentAction) {
case Helper.ATTACHMENT_ALWAYS: case Helper.ATTACHMENT_ALWAYS:
radioGroup.check(R.id.set_attachment_always); set_attachment_group.setSelection(0);
break; break;
case Helper.ATTACHMENT_WIFI: case Helper.ATTACHMENT_WIFI:
radioGroup.check(R.id.set_attachment_wifi); set_attachment_group.setSelection(1);
break; break;
case Helper.ATTACHMENT_ASK: case Helper.ATTACHMENT_ASK:
radioGroup.check(R.id.set_attachment_ask); set_attachment_group.setSelection(2);
break; break;
} }
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
set_attachment_group.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (checkedId) { if (count9 > 0) {
case R.id.set_attachment_always: SharedPreferences.Editor editor = sharedpreferences.edit();
SharedPreferences.Editor editor = sharedpreferences.edit(); switch (position) {
editor.putInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS); case 0:
editor.apply(); editor.putInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ALWAYS);
break; editor.apply();
case R.id.set_attachment_wifi: break;
editor = sharedpreferences.edit(); case 1:
editor.putInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_WIFI); editor.putInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_WIFI);
editor.apply(); editor.apply();
break; break;
case R.id.set_attachment_ask: case 2:
editor = sharedpreferences.edit(); editor.putInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ASK);
editor.putInt(Helper.SET_ATTACHMENT_ACTION, Helper.ATTACHMENT_ASK); editor.apply();
editor.apply(); break;
break; }
} }
count9++;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
} }
}); });
int videoMode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT); int videoMode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT);
@ -1038,58 +1054,59 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
} }
}); });
Spinner set_mode = rootView.findViewById(R.id.set_mode);
String[] mode_labels = {context.getString(R.string.set_normal), context.getString(R.string.set_compact), context.getString(R.string.set_console)};
ArrayAdapter<String> adapterMode = new ArrayAdapter<>(context,
android.R.layout.simple_spinner_dropdown_item,mode_labels );
set_mode.setAdapter(adapterMode);
boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false); boolean compact_mode = sharedpreferences.getBoolean(Helper.SET_COMPACT_MODE, false);
boolean console_mode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false); boolean console_mode = sharedpreferences.getBoolean(Helper.SET_CONSOLE_MODE, false);
RadioGroup set_mode = rootView.findViewById(R.id.set_mode);
if (compact_mode) { if (compact_mode) {
set_mode.check(R.id.set_compact_mode); set_mode.setSelection(1);
} else if (console_mode) { } else if (console_mode) {
set_mode.check(R.id.set_console_mode); set_mode.setSelection(2);
} else { } else {
set_mode.check(R.id.set_normal_mode); set_mode.setSelection(0);
} }
set_mode.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
set_mode.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onCheckedChanged(RadioGroup group, int checkedId) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (checkedId) { if (count8 > 0) {
case R.id.set_compact_mode: SharedPreferences.Editor editor = sharedpreferences.edit();
SharedPreferences.Editor editor = sharedpreferences.edit(); switch (position) {
editor.putBoolean(Helper.SET_COMPACT_MODE, true); case 0:
editor.putBoolean(Helper.SET_CONSOLE_MODE, false); editor = sharedpreferences.edit();
editor.apply(); editor.putBoolean(Helper.SET_COMPACT_MODE, false);
break; editor.putBoolean(Helper.SET_CONSOLE_MODE, false);
case R.id.set_console_mode: editor.apply();
editor = sharedpreferences.edit(); break;
editor.putBoolean(Helper.SET_COMPACT_MODE, false); case 1:
editor.putBoolean(Helper.SET_CONSOLE_MODE, true); editor.putBoolean(Helper.SET_COMPACT_MODE, true);
editor.apply(); editor.putBoolean(Helper.SET_CONSOLE_MODE, false);
break; editor.apply();
case R.id.set_normal_mode: break;
editor = sharedpreferences.edit(); case 2:
editor.putBoolean(Helper.SET_COMPACT_MODE, false); editor = sharedpreferences.edit();
editor.putBoolean(Helper.SET_CONSOLE_MODE, false); editor.putBoolean(Helper.SET_COMPACT_MODE, false);
editor.apply(); editor.putBoolean(Helper.SET_CONSOLE_MODE, true);
break; editor.apply();
break;
}
} }
count8++;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
} }
}); });
boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true); boolean share_details = sharedpreferences.getBoolean(Helper.SET_SHARE_DETAILS, true);
final SwitchCompat set_share_details = rootView.findViewById(R.id.set_share_details); final SwitchCompat set_share_details = rootView.findViewById(R.id.set_share_details);
set_share_details.setChecked(share_details); set_share_details.setChecked(share_details);
@ -2318,7 +2335,7 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
lv_translator_manager.setAdapter(translatorManager); lv_translator_manager.setAdapter(translatorManager);
if( type == LANGUAGE) { if( type == LANGUAGE) {
new RetrieveRemoteDataAsyncTask(context, "ButterflyOfFire", "mstdn.fr", ContentSettingsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); asyncTask = new RetrieveRemoteDataAsyncTask(context, "ButterflyOfFire", "mstdn.fr", ContentSettingsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
String currentLanguage = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, Helper.localeToStringStorage(Locale.getDefault())); String currentLanguage = sharedpreferences.getString(Helper.SET_DEFAULT_LOCALE_NEW, Helper.localeToStringStorage(Locale.getDefault()));
@ -2548,7 +2565,13 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
this.context = context; this.context = context;
} }
public void onDestroy() {
super.onDestroy();
if( type == LANGUAGE) {
if (asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
}
}
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper //From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
@TargetApi(Build.VERSION_CODES.KITKAT) @TargetApi(Build.VERSION_CODES.KITKAT)
@ -2637,6 +2660,8 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
return null; return null;
} }
/** /**
* @param uri The Uri to check. * @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider. * @return Whether the Uri authority is ExternalStorageProvider.

View File

@ -1409,37 +1409,24 @@
android:visibility="gone"> android:visibility="gone">
<!-- COMPACT MODE --> <!-- COMPACT MODE -->
<TextView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/set_mode" android:layout_gravity="center_vertical"
android:textSize="16sp" />
<RadioGroup
android:id="@+id/set_mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/settings_option_margin"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
<RadioButton
android:id="@+id/set_normal_mode"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/set_normal" /> android:layout_gravity="center_vertical"
android:text="@string/set_mode"
android:textSize="16sp" />
<RadioButton <Spinner
android:id="@+id/set_compact_mode" android:id="@+id/set_mode"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/set_compact" /> android:entries="@array/led_colours" />
</LinearLayout>
<RadioButton
android:id="@+id/set_console_mode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_console" />
</RadioGroup>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -1729,38 +1716,25 @@
</LinearLayout> </LinearLayout>
<TextView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/settings_option_margin" android:layout_gravity="center_vertical"
android:text="@string/set_attachment_action"
android:textSize="16sp" />
<RadioGroup
android:id="@+id/set_attachment_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/settings_option_margin"
android:orientation="horizontal"> android:orientation="horizontal">
<TextView
<RadioButton
android:id="@+id/set_attachment_always"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/set_attachment_always" /> android:layout_gravity="center_vertical"
android:text="@string/set_attachment_action"
android:textSize="16sp" />
<RadioButton <Spinner
android:id="@+id/set_attachment_wifi" android:id="@+id/set_attachment_group"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/set_attachment_wifi" /> android:entries="@array/led_colours" />
</LinearLayout>
<RadioButton
android:id="@+id/set_attachment_ask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_attachment_ask" />
</RadioGroup>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"