Improve settings with notifications
This commit is contained in:
parent
b4ec682c81
commit
a488d0f419
|
@ -79,7 +79,6 @@ public class SettingsFragment extends Fragment {
|
|||
|
||||
private Context context;
|
||||
private static final int ACTIVITY_CHOOSE_FILE = 411;
|
||||
private static final int ACTIVITY_CHOOSE_SOUND = 412;
|
||||
private TextView set_folder;
|
||||
int count1, count2, count3 = 0;
|
||||
private EditText your_api_key;
|
||||
|
@ -544,17 +543,7 @@ public class SettingsFragment extends Fragment {
|
|||
});
|
||||
|
||||
|
||||
Button set_notif_sound = rootView.findViewById(R.id.set_notif_sound);
|
||||
set_notif_sound.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, context.getString(R.string.select_sound));
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
|
||||
startActivityForResult(intent, ACTIVITY_CHOOSE_SOUND);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
LinearLayout toot_visibility_container = rootView.findViewById(R.id.toot_visibility_container);
|
||||
|
@ -764,16 +753,18 @@ public class SettingsFragment extends Fragment {
|
|||
}
|
||||
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode != RESULT_OK) return;
|
||||
|
||||
|
||||
if(requestCode == ACTIVITY_CHOOSE_FILE) {
|
||||
Uri treeUri = data.getData();
|
||||
Uri docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri,
|
||||
DocumentsContract.getTreeDocumentId(treeUri));
|
||||
Uri docUri = null;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||
docUri = DocumentsContract.buildDocumentUriUsingTree(treeUri,
|
||||
DocumentsContract.getTreeDocumentId(treeUri));
|
||||
}
|
||||
try{
|
||||
String path = getPath(context, docUri);
|
||||
if( path == null )
|
||||
|
@ -787,16 +778,6 @@ public class SettingsFragment extends Fragment {
|
|||
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
}else if (requestCode == ACTIVITY_CHOOSE_SOUND){
|
||||
try{
|
||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.SET_NOTIF_SOUND, uri.toString());
|
||||
editor.apply();
|
||||
}catch (Exception e){
|
||||
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,9 +16,14 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
@ -42,6 +47,7 @@ import android.widget.Toast;
|
|||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.compareDate;
|
||||
|
||||
|
||||
|
@ -54,7 +60,7 @@ public class SettingsNotificationsFragment extends Fragment {
|
|||
|
||||
private Context context;
|
||||
private int style;
|
||||
|
||||
private static final int ACTIVITY_CHOOSE_SOUND = 412;
|
||||
int count = 0;
|
||||
|
||||
@Override
|
||||
|
@ -129,6 +135,33 @@ public class SettingsNotificationsFragment extends Fragment {
|
|||
settings_time_to.setText(time_to);
|
||||
|
||||
|
||||
Button set_notif_sound = rootView.findViewById(R.id.set_notif_sound);
|
||||
set_notif_sound.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TITLE, context.getString(R.string.select_sound));
|
||||
intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, (Uri) null);
|
||||
startActivityForResult(intent, ACTIVITY_CHOOSE_SOUND);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
boolean enable_time_slot = sharedpreferences.getBoolean(Helper.SET_ENABLE_TIME_SLOT, true);
|
||||
final CheckBox set_enable_time_slot = rootView.findViewById(R.id.set_enable_time_slot);
|
||||
set_enable_time_slot.setChecked(enable_time_slot);
|
||||
|
||||
set_enable_time_slot.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.SET_ENABLE_TIME_SLOT, set_enable_time_slot.isChecked());
|
||||
editor.apply();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
settings_time_from.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -314,7 +347,22 @@ public class SettingsNotificationsFragment extends Fragment {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode != RESULT_OK) return;
|
||||
|
||||
if (requestCode == ACTIVITY_CHOOSE_SOUND){
|
||||
try{
|
||||
Uri uri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.SET_NOTIF_SOUND, uri.toString());
|
||||
editor.apply();
|
||||
}catch (Exception e){
|
||||
Toast.makeText(context, R.string.toast_error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onCreate(Bundle saveInstance) {
|
||||
super.onCreate(saveInstance);
|
||||
|
|
|
@ -224,6 +224,7 @@ public class Helper {
|
|||
public static final String LAST_LIST = "last_list";
|
||||
public static final String LAST_LIST_NAME = "last_list_name";
|
||||
|
||||
|
||||
//Notifications
|
||||
public static final int NOTIFICATION_INTENT = 1;
|
||||
public static final int HOME_TIMELINE_INTENT = 2;
|
||||
|
@ -263,6 +264,7 @@ public class Helper {
|
|||
public static final String SET_COMPACT_MODE = "set_compact_mode";
|
||||
public static final String SET_SHARE_DETAILS = "set_share_details";
|
||||
public static final String SET_NOTIF_SOUND = "set_notif_sound";
|
||||
public static final String SET_ENABLE_TIME_SLOT = "set_enable_time_slot";
|
||||
public static final int S_512KO = 1;
|
||||
public static final int S_1MO = 2;
|
||||
public static final int S_2MO = 3;
|
||||
|
@ -1674,6 +1676,9 @@ public class Helper {
|
|||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
if( !notify)
|
||||
return false;
|
||||
boolean enable_time_slot = sharedpreferences.getBoolean(Helper.SET_ENABLE_TIME_SLOT, true);
|
||||
if( ! enable_time_slot)
|
||||
return true;
|
||||
String dateIni = sharedpreferences.getString(Helper.SET_TIME_FROM, "07:00");
|
||||
String dateEnd = sharedpreferences.getString(Helper.SET_TIME_TO, "22:00");
|
||||
Calendar now = Calendar.getInstance();
|
||||
|
|
|
@ -157,14 +157,6 @@
|
|||
android:text="@string/send_crash_report"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/set_notif_sound"
|
||||
android:gravity="center"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:tint="@android:color/white"
|
||||
android:text="@string/set_notif_sound"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<!-- Resize pictures -->
|
||||
<LinearLayout
|
||||
android:layout_marginTop="10dp"
|
||||
|
|
|
@ -157,14 +157,7 @@
|
|||
android:text="@string/send_crash_report"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/set_notif_sound"
|
||||
android:gravity="center"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:tint="@android:color/white"
|
||||
android:text="@string/set_notif_sound"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
<!-- Resize pictures -->
|
||||
<LinearLayout
|
||||
|
|
|
@ -59,6 +59,16 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/set_notif_sound"
|
||||
android:gravity="center"
|
||||
style="@style/Base.Widget.AppCompat.Button.Colored"
|
||||
android:tint="@android:color/white"
|
||||
android:textColor="@color/white"
|
||||
android:text="@string/set_notif_sound"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
<!-- NOTIFICATIONS SETTINGS -->
|
||||
<TextView
|
||||
android:text="@string/settings_title_notifications"
|
||||
|
@ -118,6 +128,11 @@
|
|||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
<CheckBox
|
||||
android:id="@+id/set_enable_time_slot"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/set_enable_time_slot"
|
||||
android:layout_height="wrap_content" />
|
||||
<LinearLayout
|
||||
style="?attr/shapeBorder"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -619,6 +619,7 @@
|
|||
<string name="channel_notif_media">Media Download</string>
|
||||
<string name="set_notif_sound">Change notification sound</string>
|
||||
<string name="select_sound">Select Tone</string>
|
||||
<string name="set_enable_time_slot">Enable time slot</string>
|
||||
|
||||
<string-array name="filter_expire">
|
||||
<item>Never</item>
|
||||
|
|
Loading…
Reference in New Issue