2017-06-24 11:38:18 +02:00
|
|
|
package fr.gouv.etalab.mastodon.fragments;
|
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2017-07-10 10:33:24 +02:00
|
|
|
* This file is a part of Mastalab
|
2017-06-24 11:38:18 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
2017-07-10 10:33:24 +02:00
|
|
|
* Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-06-24 11:38:18 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2017-08-04 11:11:27 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Mastalab; if not,
|
2017-06-24 11:38:18 +02:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-08-07 01:53:33 +02:00
|
|
|
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.annotation.TargetApi;
|
2017-08-15 18:07:23 +02:00
|
|
|
import android.support.v7.app.AlertDialog;
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.content.ContentUris;
|
2017-06-24 11:38:18 +02:00
|
|
|
import android.content.Context;
|
2017-08-07 10:20:44 +02:00
|
|
|
import android.content.DialogInterface;
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.content.Intent;
|
2017-06-24 11:38:18 +02:00
|
|
|
import android.content.SharedPreferences;
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.database.Cursor;
|
2017-08-07 10:20:44 +02:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.net.Uri;
|
2017-06-24 11:38:18 +02:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.os.Environment;
|
|
|
|
import android.provider.DocumentsContract;
|
|
|
|
import android.provider.MediaStore;
|
2017-06-24 11:38:18 +02:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
import android.support.v7.widget.SwitchCompat;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2017-08-12 09:53:07 +02:00
|
|
|
import android.widget.AdapterView;
|
2017-08-07 10:20:44 +02:00
|
|
|
import android.widget.ArrayAdapter;
|
2017-06-24 11:38:18 +02:00
|
|
|
import android.widget.CheckBox;
|
|
|
|
import android.widget.CompoundButton;
|
2017-08-07 10:20:44 +02:00
|
|
|
import android.widget.ImageView;
|
2017-06-24 11:38:18 +02:00
|
|
|
import android.widget.LinearLayout;
|
2017-08-07 01:53:33 +02:00
|
|
|
import android.widget.SeekBar;
|
2017-08-12 09:53:07 +02:00
|
|
|
import android.widget.Spinner;
|
2017-06-27 19:18:46 +02:00
|
|
|
import android.widget.TextView;
|
2017-08-07 10:20:44 +02:00
|
|
|
import android.widget.Toast;
|
2017-07-23 17:09:23 +02:00
|
|
|
|
|
|
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
2017-08-07 10:20:44 +02:00
|
|
|
import fr.gouv.etalab.mastodon.client.Entities.Account;
|
2017-06-24 11:38:18 +02:00
|
|
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
2017-08-07 10:20:44 +02:00
|
|
|
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
|
|
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
2017-06-24 11:38:18 +02:00
|
|
|
import mastodon.etalab.gouv.fr.mastodon.R;
|
|
|
|
|
2017-06-27 19:18:46 +02:00
|
|
|
import static android.app.Activity.RESULT_OK;
|
2017-07-23 17:09:23 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
|
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
|
2017-08-07 10:20:44 +02:00
|
|
|
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
2017-06-27 19:18:46 +02:00
|
|
|
|
2017-06-24 11:38:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 24/06/2017.
|
|
|
|
* Fragment for settings, yes I didn't use PreferenceFragment :)
|
|
|
|
*/
|
|
|
|
public class SettingsFragment extends Fragment {
|
|
|
|
|
|
|
|
|
|
|
|
private Context context;
|
2017-06-27 19:18:46 +02:00
|
|
|
private static final int ACTIVITY_CHOOSE_FILE = 411;
|
|
|
|
private TextView set_folder;
|
2017-08-13 18:31:44 +02:00
|
|
|
int count = 0;
|
2017-08-25 15:53:04 +02:00
|
|
|
int count2 = 0;
|
2017-06-24 11:38:18 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
|
|
|
2017-08-07 10:20:44 +02:00
|
|
|
final View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
|
2017-06-24 11:38:18 +02:00
|
|
|
context = getContext();
|
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
|
2017-08-13 11:30:28 +02:00
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
2017-06-24 11:38:18 +02:00
|
|
|
|
2017-08-08 18:15:37 +02:00
|
|
|
boolean auto_store = sharedpreferences.getBoolean(Helper.SET_AUTO_STORE, true);
|
2017-06-24 11:38:18 +02:00
|
|
|
|
2017-07-15 14:59:09 +02:00
|
|
|
final CheckBox set_auto_store = (CheckBox) rootView.findViewById(R.id.set_auto_store);
|
|
|
|
set_auto_store.setChecked(auto_store);
|
|
|
|
set_auto_store.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_AUTO_STORE, set_auto_store.isChecked());
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
2017-08-25 14:30:55 +02:00
|
|
|
|
2017-06-24 11:38:18 +02:00
|
|
|
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
|
|
|
final CheckBox set_show_error_messages = (CheckBox) rootView.findViewById(R.id.set_show_error_messages);
|
|
|
|
set_show_error_messages.setChecked(show_error_messages);
|
|
|
|
|
|
|
|
set_show_error_messages.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_SHOW_ERROR_MESSAGES, set_show_error_messages.isChecked());
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-15 09:02:46 +02:00
|
|
|
boolean show_media_urls = sharedpreferences.getBoolean(Helper.SET_MEDIA_URLS, true);
|
|
|
|
final CheckBox set_auto_add_media_url = (CheckBox) rootView.findViewById(R.id.set_auto_add_media_url);
|
|
|
|
set_auto_add_media_url.setChecked(show_media_urls);
|
|
|
|
|
|
|
|
set_auto_add_media_url.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_MEDIA_URLS, set_auto_add_media_url.isChecked());
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
2017-06-24 11:38:18 +02:00
|
|
|
|
2017-08-18 17:50:54 +02:00
|
|
|
boolean preview_reply = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES, true);
|
2017-08-16 19:10:49 +02:00
|
|
|
final CheckBox set_preview_reply = (CheckBox) rootView.findViewById(R.id.set_preview_reply);
|
2017-08-20 12:11:58 +02:00
|
|
|
final LinearLayout set_preview_reply_pp_container = (LinearLayout) rootView.findViewById(R.id.set_preview_reply_pp_container);
|
|
|
|
final SwitchCompat set_preview_reply_pp = (SwitchCompat) rootView.findViewById(R.id.set_preview_reply_pp);
|
2017-08-16 19:10:49 +02:00
|
|
|
set_preview_reply.setChecked(preview_reply);
|
|
|
|
|
|
|
|
set_preview_reply.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_PREVIEW_REPLIES, set_preview_reply.isChecked());
|
|
|
|
editor.apply();
|
2017-08-20 12:11:58 +02:00
|
|
|
if( !set_preview_reply.isChecked()){
|
|
|
|
set_preview_reply_pp_container.setVisibility(View.GONE);
|
|
|
|
}else{
|
|
|
|
set_preview_reply_pp_container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2017-08-16 19:10:49 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-20 12:11:58 +02:00
|
|
|
if( !preview_reply){
|
|
|
|
set_preview_reply_pp_container.setVisibility(View.GONE);
|
|
|
|
}else{
|
|
|
|
set_preview_reply_pp_container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
boolean preview_reply_pp = sharedpreferences.getBoolean(Helper.SET_PREVIEW_REPLIES_PP, true);
|
|
|
|
set_preview_reply_pp.setChecked(preview_reply_pp);
|
|
|
|
set_preview_reply_pp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_PREVIEW_REPLIES_PP, isChecked);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-24 11:38:18 +02:00
|
|
|
boolean notif_validation = sharedpreferences.getBoolean(Helper.SET_NOTIF_VALIDATION, true);
|
|
|
|
final CheckBox set_share_validation = (CheckBox) rootView.findViewById(R.id.set_share_validation);
|
|
|
|
set_share_validation.setChecked(notif_validation);
|
|
|
|
|
|
|
|
set_share_validation.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_NOTIF_VALIDATION, set_share_validation.isChecked());
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
final CheckBox set_embedded_browser = (CheckBox) rootView.findViewById(R.id.set_embedded_browser);
|
|
|
|
final LinearLayout set_javascript_container = (LinearLayout) rootView.findViewById(R.id.set_javascript_container);
|
|
|
|
final SwitchCompat set_javascript = (SwitchCompat) rootView.findViewById(R.id.set_javascript);
|
|
|
|
boolean javascript = sharedpreferences.getBoolean(Helper.SET_JAVASCRIPT, true);
|
|
|
|
boolean embedded_browser = sharedpreferences.getBoolean(Helper.SET_EMBEDDED_BROWSER, true);
|
|
|
|
if( !embedded_browser){
|
|
|
|
set_javascript_container.setVisibility(View.GONE);
|
|
|
|
}else{
|
|
|
|
set_javascript_container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
set_embedded_browser.setChecked(embedded_browser);
|
|
|
|
set_embedded_browser.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_EMBEDDED_BROWSER, set_embedded_browser.isChecked());
|
|
|
|
editor.apply();
|
|
|
|
if( !set_embedded_browser.isChecked()){
|
|
|
|
set_javascript_container.setVisibility(View.GONE);
|
|
|
|
}else{
|
|
|
|
set_javascript_container.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
set_javascript.setChecked(javascript);
|
|
|
|
set_javascript.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_JAVASCRIPT, isChecked);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
final LinearLayout set_cookies_container = (LinearLayout) rootView.findViewById(R.id.set_cookies_container);
|
|
|
|
final SwitchCompat set_cookies = (SwitchCompat) rootView.findViewById(R.id.set_cookies);
|
|
|
|
boolean cookies = sharedpreferences.getBoolean(Helper.SET_COOKIES, false);
|
|
|
|
|
|
|
|
set_cookies.setChecked(cookies);
|
|
|
|
set_cookies.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putBoolean(Helper.SET_COOKIES, isChecked);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
set_cookies_container.setVisibility(View.VISIBLE);
|
|
|
|
}else {
|
|
|
|
set_cookies_container.setVisibility(View.GONE);
|
|
|
|
}
|
2017-07-17 15:22:59 +02:00
|
|
|
final String targeted_folder = sharedpreferences.getString(Helper.SET_FOLDER_RECORD, Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath());
|
2017-06-27 19:18:46 +02:00
|
|
|
|
|
|
|
set_folder = (TextView) rootView.findViewById(R.id.set_folder);
|
|
|
|
set_folder.setText(targeted_folder);
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
set_folder.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
|
|
|
@SuppressLint("InlinedApi") Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
|
|
|
startActivityForResult(intent, ACTIVITY_CHOOSE_FILE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}else {
|
|
|
|
LinearLayout file_chooser = (LinearLayout) rootView.findViewById(R.id.file_chooser);
|
|
|
|
file_chooser.setVisibility(View.GONE);
|
|
|
|
}
|
2017-06-24 11:38:18 +02:00
|
|
|
|
2017-06-30 17:09:07 +02:00
|
|
|
final SwitchCompat set_night_mode = (SwitchCompat) rootView.findViewById(R.id.set_night_mode);
|
|
|
|
set_night_mode.setChecked(theme == Helper.THEME_DARK);
|
|
|
|
set_night_mode.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putInt(Helper.SET_THEME, isChecked?Helper.THEME_DARK:Helper.THEME_LIGHT);
|
|
|
|
editor.apply();
|
|
|
|
if( isChecked){
|
|
|
|
getActivity().setTheme(R.style.AppThemeDark);
|
|
|
|
}else {
|
|
|
|
getActivity().setTheme(R.style.AppTheme);
|
|
|
|
}
|
|
|
|
getActivity().recreate();
|
2017-07-23 17:09:23 +02:00
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
|
|
|
|
startActivity(intent);
|
|
|
|
|
2017-06-30 17:09:07 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-07 01:53:33 +02:00
|
|
|
// NSFW Timeout
|
|
|
|
SeekBar nsfwTimeoutSeekBar = (SeekBar) rootView.findViewById(R.id.set_nsfw_timeout);
|
|
|
|
final TextView set_nsfw_timeout_value = (TextView) rootView.findViewById(R.id.set_nsfw_timeout_value);
|
|
|
|
|
|
|
|
nsfwTimeoutSeekBar.setMax(30);
|
|
|
|
|
|
|
|
int nsfwTimeout = sharedpreferences.getInt(Helper.SET_NSFW_TIMEOUT, 5);
|
|
|
|
|
|
|
|
nsfwTimeoutSeekBar.setProgress(nsfwTimeout);
|
|
|
|
set_nsfw_timeout_value.setText(String.valueOf(nsfwTimeout));
|
|
|
|
|
|
|
|
nsfwTimeoutSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onStopTrackingTouch(SeekBar seekBar) {}
|
|
|
|
@Override
|
|
|
|
public void onStartTrackingTouch(SeekBar seekBar) {}
|
|
|
|
@Override
|
|
|
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
|
|
|
|
|
|
|
set_nsfw_timeout_value.setText(String.valueOf(progress));
|
|
|
|
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putInt(Helper.SET_NSFW_TIMEOUT, progress);
|
|
|
|
editor.apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-07 10:20:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
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) {
|
2017-08-15 18:07:23 +02:00
|
|
|
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
|
2017-08-07 10:20:44 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-08-12 13:48:06 +02:00
|
|
|
final Spinner tabs_layout_spinner = (Spinner) rootView.findViewById(R.id.tabs_layout_spinner);
|
2017-08-12 18:41:35 +02:00
|
|
|
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
|
2017-08-12 09:53:07 +02:00
|
|
|
R.array.settings_menu_tabs, android.R.layout.simple_spinner_item);
|
|
|
|
tabs_layout_spinner.setAdapter(adapter);
|
|
|
|
|
|
|
|
int positionSpinner = (sharedpreferences.getInt(Helper.SET_TABS, Helper.THEME_TABS) - 1);
|
|
|
|
tabs_layout_spinner.setSelection(positionSpinner);
|
2017-08-13 18:31:44 +02:00
|
|
|
tabs_layout_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if( count > 0){
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putInt(Helper.SET_TABS, (position + 1));
|
|
|
|
editor.apply();
|
|
|
|
Helper.switchLayout(getActivity());
|
|
|
|
getActivity().recreate();
|
|
|
|
Intent intent = new Intent(context, MainActivity.class);
|
|
|
|
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
|
|
|
|
startActivity(intent);
|
|
|
|
}else {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2017-08-12 09:53:07 +02:00
|
|
|
|
2017-08-13 18:31:44 +02:00
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
2017-08-12 09:53:07 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2017-08-12 13:48:06 +02:00
|
|
|
|
2017-08-25 15:53:04 +02:00
|
|
|
final Spinner translation_layout_spinner = (Spinner) rootView.findViewById(R.id.translation_layout_spinner);
|
|
|
|
ArrayAdapter<CharSequence> adapterTrans = ArrayAdapter.createFromResource(getActivity(),
|
|
|
|
R.array.settings_translation, android.R.layout.simple_spinner_item);
|
|
|
|
translation_layout_spinner.setAdapter(adapterTrans);
|
|
|
|
|
|
|
|
int positionSpinnerTrans = (sharedpreferences.getInt(Helper.SET_TRANSLATOR, Helper.TRANS_YANDEX));
|
|
|
|
translation_layout_spinner.setSelection(positionSpinnerTrans);
|
|
|
|
translation_layout_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
|
if( count2 > 0){
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putInt(Helper.SET_TRANSLATOR, position );
|
|
|
|
editor.apply();
|
|
|
|
}else {
|
|
|
|
count2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-24 11:38:18 +02:00
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
2017-08-07 10:20:44 +02:00
|
|
|
|
|
|
|
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 {
|
2017-08-13 18:31:44 +02:00
|
|
|
changeDrawableColor(context, R.drawable.ic_action_globe,R.color.white);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_lock_open,R.color.white);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_action_lock_closed,R.color.white);
|
|
|
|
changeDrawableColor(context, R.drawable.ic_local_post_office,R.color.white);
|
2017-08-07 10:20:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-06-27 19:18:46 +02:00
|
|
|
@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));
|
|
|
|
String path = getPath(context, docUri);
|
|
|
|
if( path == null )
|
2017-07-17 15:22:59 +02:00
|
|
|
path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
|
2017-06-27 19:18:46 +02:00
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
|
|
|
editor.putString(Helper.SET_FOLDER_RECORD, path);
|
|
|
|
editor.apply();
|
|
|
|
set_folder.setText(path);
|
|
|
|
}
|
|
|
|
}
|
2017-06-24 11:38:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle saveInstance) {
|
|
|
|
super.onCreate(saveInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
2017-06-27 19:18:46 +02:00
|
|
|
//From: https://gist.github.com/asifmujteba/d89ba9074bc941de1eaa#file-asfurihelper
|
|
|
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
|
|
public static String getPath(final Context context, final Uri uri) {
|
|
|
|
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
|
|
|
// DocumentProvider
|
|
|
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
|
|
|
// ExternalStorageProvider
|
|
|
|
if (isExternalStorageDocument(uri)) {
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
final String type = split[0];
|
|
|
|
|
|
|
|
if ("primary".equalsIgnoreCase(type)) {
|
|
|
|
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// DownloadsProvider
|
|
|
|
else if (isDownloadsDocument(uri)) {
|
|
|
|
|
|
|
|
final String id = DocumentsContract.getDocumentId(uri);
|
|
|
|
final Uri contentUri = ContentUris.withAppendedId(
|
|
|
|
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
|
|
|
|
|
|
|
return getDataColumn(context, contentUri, null, null);
|
|
|
|
}
|
|
|
|
// MediaProvider
|
|
|
|
else if (isMediaDocument(uri)) {
|
|
|
|
final String docId = DocumentsContract.getDocumentId(uri);
|
|
|
|
final String[] split = docId.split(":");
|
|
|
|
final String type = split[0];
|
|
|
|
|
|
|
|
Uri contentUri = null;
|
|
|
|
if ("image".equals(type)) {
|
|
|
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
} else if ("video".equals(type)) {
|
|
|
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
} else if ("audio".equals(type)) {
|
|
|
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String selection = "_id=?";
|
|
|
|
final String[] selectionArgs = new String[] {
|
|
|
|
split[1]
|
|
|
|
};
|
|
|
|
return getDataColumn(context, contentUri, selection, selectionArgs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// MediaStore (and general)
|
|
|
|
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
|
|
|
|
|
|
|
// Return the remote address
|
|
|
|
if (isGooglePhotosUri(uri))
|
|
|
|
return uri.getLastPathSegment();
|
|
|
|
|
|
|
|
return getDataColumn(context, uri, null, null);
|
|
|
|
}
|
|
|
|
// File
|
|
|
|
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
|
|
|
return uri.getPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
public static String getDataColumn(Context context, Uri uri, String selection,
|
|
|
|
String[] selectionArgs) {
|
|
|
|
|
|
|
|
Cursor cursor = null;
|
|
|
|
final String column = "_data";
|
|
|
|
final String[] projection = {
|
|
|
|
column
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
|
|
|
null);
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
final int index = cursor.getColumnIndexOrThrow(column);
|
|
|
|
return cursor.getString(index);
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is ExternalStorageProvider.
|
|
|
|
*/
|
|
|
|
public static boolean isExternalStorageDocument(Uri uri) {
|
|
|
|
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is DownloadsProvider.
|
|
|
|
*/
|
|
|
|
public static boolean isDownloadsDocument(Uri uri) {
|
|
|
|
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
|
|
|
}
|
2017-06-24 11:38:18 +02:00
|
|
|
|
2017-06-27 19:18:46 +02:00
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is MediaProvider.
|
|
|
|
*/
|
|
|
|
public static boolean isMediaDocument(Uri uri) {
|
|
|
|
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
|
|
|
}
|
2017-06-24 11:38:18 +02:00
|
|
|
|
2017-06-27 19:18:46 +02:00
|
|
|
/**
|
|
|
|
* @param uri The Uri to check.
|
|
|
|
* @return Whether the Uri authority is Google Photos.
|
|
|
|
*/
|
|
|
|
public static boolean isGooglePhotosUri(Uri uri) {
|
|
|
|
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
|
|
|
|
}
|
2017-06-24 11:38:18 +02:00
|
|
|
|
|
|
|
}
|