Allows to manage the default visibility of the toots for non locked accounts. Cf: https://bitbucket.org/tom79/mastodon_etalab/issues/5/set-default-level-of-publishing
This commit is contained in:
parent
0b122e3c6c
commit
4b7cfa07f2
|
@ -337,8 +337,21 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
|
|||
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
|
||||
}else {
|
||||
if( tootReply == null){
|
||||
visibility = "public";
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_globe);
|
||||
visibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), "public");
|
||||
switch (visibility) {
|
||||
case "public":
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_globe);
|
||||
break;
|
||||
case "unlisted":
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
|
||||
break;
|
||||
case "private":
|
||||
toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
|
||||
break;
|
||||
case "direct":
|
||||
toot_visibility.setImageResource(R.drawable.ic_local_post_office);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,11 +16,14 @@ package fr.gouv.etalab.mastodon.fragments;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -32,19 +35,29 @@ import android.support.v7.widget.SwitchCompat;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||
import fr.gouv.etalab.mastodon.activities.TootActivity;
|
||||
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import mastodon.etalab.gouv.fr.mastodon.R;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -61,7 +74,7 @@ public class SettingsFragment extends Fragment {
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
final View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
|
||||
context = getContext();
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
|
||||
|
@ -240,9 +253,108 @@ public class SettingsFragment extends Fragment {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
LinearLayout toot_visibility_container = (LinearLayout) rootView.findViewById(R.id.toot_visibility_container);
|
||||
String prefKeyOauthTokenT = sharedpreferences.getString(Helper.PREF_KEY_OAUTH_TOKEN, null);
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
final Account account = new AccountDAO(context, db).getAccountByToken(prefKeyOauthTokenT);
|
||||
final ImageView set_toot_visibility = (ImageView) rootView.findViewById(R.id.set_toot_visibility);
|
||||
//Only displayed for non locked accounts
|
||||
if (account != null && !account.isLocked()) {
|
||||
String tootVisibility = sharedpreferences.getString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), "public");
|
||||
switch (tootVisibility) {
|
||||
case "public":
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_action_globe);
|
||||
break;
|
||||
case "unlisted":
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
|
||||
break;
|
||||
case "private":
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
|
||||
break;
|
||||
case "direct":
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_local_post_office);
|
||||
break;
|
||||
}
|
||||
changeColor();
|
||||
}else {
|
||||
toot_visibility_container.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
set_toot_visibility.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
||||
dialog.setTitle(R.string.toot_visibility_tilte);
|
||||
final String[] stringArray = getResources().getStringArray(R.array.toot_visibility);
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, stringArray);
|
||||
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int position) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
dialog.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int position) {
|
||||
String visibility = "public";
|
||||
|
||||
switch (position){
|
||||
case 0:
|
||||
visibility = "public";
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_action_globe);
|
||||
break;
|
||||
case 1:
|
||||
visibility = "unlisted";
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_action_lock_open);
|
||||
break;
|
||||
case 2:
|
||||
visibility = "private";
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_action_lock_closed);
|
||||
break;
|
||||
case 3:
|
||||
visibility = "direct";
|
||||
set_toot_visibility.setImageResource(R.drawable.ic_local_post_office);
|
||||
break;
|
||||
}
|
||||
if( account != null) {
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putString(Helper.SET_TOOT_VISIBILITY + "@" + account.getAcct() + "@" + account.getInstance(), visibility);
|
||||
editor.apply();
|
||||
Toast.makeText(context, context.getString(R.string.toast_visibility_changed, "@" + account.getAcct() + "@" + account.getInstance()), Toast.LENGTH_SHORT).show();
|
||||
}else {
|
||||
Toast.makeText(context, R.string.toast_error,Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
changeColor();
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
private void changeColor(){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
if( theme == Helper.THEME_DARK){
|
||||
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.dark_text);
|
||||
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.dark_text);
|
||||
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.dark_text);
|
||||
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.dark_text);
|
||||
}else {
|
||||
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.black);
|
||||
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.black);
|
||||
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.black);
|
||||
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.black);
|
||||
}
|
||||
|
||||
}
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
|
|
@ -205,6 +205,7 @@ public class Helper {
|
|||
public static final String SET_JAVASCRIPT = "set_javascript";
|
||||
public static final String SET_COOKIES = "set_cookies";
|
||||
public static final String SET_FOLDER_RECORD = "set_folder_record";
|
||||
public static final String SET_TOOT_VISIBILITY = "set_toot_visibility";
|
||||
|
||||
//End points
|
||||
public static final String EP_AUTHORIZE = "/oauth/authorize";
|
||||
|
|
|
@ -166,6 +166,29 @@
|
|||
android:layout_height="wrap_content"
|
||||
/>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- TOOTS visibility -->
|
||||
<LinearLayout
|
||||
android:id="@+id/toot_visibility_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/toots_visibility_tilte"/>
|
||||
<ImageButton
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:id="@+id/set_toot_visibility"
|
||||
android:padding="5dp"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_action_globe"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
<!-- NSFW Timeout -->
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -157,6 +157,7 @@
|
|||
<string name="toot_delete_media">Supprimer le média ?</string>
|
||||
<string name="toot_error_no_content">Votre pouet est vide !</string>
|
||||
<string name="toot_visibility_tilte">Visibilité du pouet</string>
|
||||
<string name="toots_visibility_tilte">Visibilité des pouets par défaut : </string>
|
||||
<string name="toot_sent">Le pouet a été envoyé !</string>
|
||||
<string name="toot_reply_content_title">Vous répondez à ce pouet :</string>
|
||||
<string name="toot_sensitive">Contenu sensible ?</string>
|
||||
|
@ -252,6 +253,7 @@
|
|||
<string name="toast_saved">Le média a été enregistré !</string>
|
||||
<string name="toast_error_translate">Une erreur est survenue lors de la traduction !</string>
|
||||
<string name="toast_toot_saved">Brouillon enregistré !</string>
|
||||
<string name="toast_visibility_changed">La visibilité des pouets a été changée pour le compte %1$s</string>
|
||||
<!-- Settings -->
|
||||
<string name="settings_title_optimisation">Optimisation du chargement</string>
|
||||
<string name="set_toots_page">Nombre de pouets par chargement</string>
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
<string name="toot_delete_media">Delete this media?</string>
|
||||
<string name="toot_error_no_content">Your toot is empty!</string>
|
||||
<string name="toot_visibility_tilte">Visibility of the toot</string>
|
||||
<string name="toots_visibility_tilte">Visibility of the toots by default: </string>
|
||||
<string name="toot_sent">The toot has been sent!</string>
|
||||
<string name="toot_reply_content_title">You are replying to this toot:</string>
|
||||
<string name="toot_sensitive">Sensitive content?</string>
|
||||
|
@ -258,7 +259,7 @@
|
|||
<string name="toast_saved">The media has been saved!</string>
|
||||
<string name="toast_error_translate">An error occurred while translating!</string>
|
||||
<string name="toast_toot_saved">Draft saved!</string>
|
||||
|
||||
<string name="toast_visibility_changed">Visibility of the toots has been changed for the account %1$s</string>
|
||||
<!-- Settings -->
|
||||
<string name="settings_title_optimisation">Optimisation of loading</string>
|
||||
<string name="set_toots_page">Number of toots per load</string>
|
||||
|
|
Loading…
Reference in New Issue