From 3f255567420b3dcc8c05f906beb8cace55a7ee8a Mon Sep 17 00:00:00 2001 From: stom79 Date: Sun, 6 Jan 2019 15:36:01 +0100 Subject: [PATCH] Settings --- .../mastodon/activities/BaseMainActivity.java | 13 ++ .../fragments/SettingsPeertubeFragment.java | 119 ++++++++++++++++++ .../gouv/etalab/mastodon/helper/Helper.java | 4 + .../res/layout/fragment_peertube_settings.xml | 47 +++++++ app/src/main/res/layout/fragment_settings.xml | 6 +- .../main/res/menu/activity_main_drawer.xml | 4 + app/src/main/res/values/strings.xml | 8 ++ 7 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java create mode 100644 app/src/main/res/layout/fragment_peertube_settings.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java index 71a4b6ac0..c0bc31abc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/BaseMainActivity.java @@ -126,6 +126,7 @@ import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment; import fr.gouv.etalab.mastodon.fragments.DisplayMutedInstanceFragment; import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment; import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment; +import fr.gouv.etalab.mastodon.fragments.SettingsPeertubeFragment; import fr.gouv.etalab.mastodon.fragments.TabLayoutScheduleFragment; import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment; import fr.gouv.etalab.mastodon.fragments.WhoToFollowFragment; @@ -1666,6 +1667,11 @@ public abstract class BaseMainActivity extends BaseActivity navigationView.setCheckedItem(R.id.nav_settings); navigationView.getMenu().performIdentifierAction(R.id.nav_settings, 0); toolbarTitle.setText(R.string.settings); + }else if( extras.getInt(INTENT_ACTION) == BACK_TO_SETTINGS){ + unCheckAllMenuItems(navigationView); + navigationView.setCheckedItem(R.id.nav_peertube_settings); + navigationView.getMenu().performIdentifierAction(R.id.nav_peertube_settings, 0); + toolbarTitle.setText(R.string.settings); }else if (extras.getInt(INTENT_ACTION) == ADD_USER_INTENT){ this.recreate(); }else if( extras.getInt(INTENT_ACTION) == BACKUP_INTENT){ @@ -2002,6 +2008,13 @@ public abstract class BaseMainActivity extends BaseActivity fragmentManager.beginTransaction() .replace(R.id.main_app_container, tabLayoutSettingsFragment, fragmentTag).commit(); + }else if (id == R.id.nav_peertube_settings) { + toot.hide(); + SettingsPeertubeFragment settingsPeertubeFragment= new SettingsPeertubeFragment(); + fragmentTag = "TABLAYOUT_PEERTUBE_SETTINGS"; + fragmentManager.beginTransaction() + .replace(R.id.main_app_container, settingsPeertubeFragment, fragmentTag).commit(); + }else if (id == R.id.nav_favorites) { toot.hide(); statusFragment = new DisplayStatusFragment(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java new file mode 100644 index 000000000..a5c0d82c7 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/SettingsPeertubeFragment.java @@ -0,0 +1,119 @@ +package fr.gouv.etalab.mastodon.fragments; +/* Copyright 2018 Thomas Schneider + * + * This file is a part of Mastalab + * + * 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. + * + * Mastalab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Mastalab; if not, + * see . */ + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Spinner; + +import fr.gouv.etalab.mastodon.R; +import fr.gouv.etalab.mastodon.activities.MainActivity; +import fr.gouv.etalab.mastodon.helper.Helper; + +import static fr.gouv.etalab.mastodon.helper.Helper.BACK_TO_SETTINGS; +import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION; + + + +/** + * Created by Thomas on 06/01/2019. + * Fragment for peertube settings + */ +public class SettingsPeertubeFragment extends Fragment { + + + private Context context; + private int count1; + + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + final View rootView = inflater.inflate(R.layout.fragment_peertube_settings, container, false); + context = getContext(); + assert context != null; + final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + + int videoMode = sharedpreferences.getInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT); + + + //Video mode + final Spinner video_mode_spinner = rootView.findViewById(R.id.set_video_mode); + ArrayAdapter video_mode_spinnerAdapter = ArrayAdapter.createFromResource(getContext(), + R.array.settings_video_mode, android.R.layout.simple_spinner_item); + video_mode_spinner.setAdapter(video_mode_spinnerAdapter); + + video_mode_spinner.setSelection(videoMode); + video_mode_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + if( count1 > 0 ) { + SharedPreferences.Editor editor = sharedpreferences.edit(); + switch (position) { + case 0: + editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_TORRENT); + editor.apply(); + break; + case 1: + editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_WEBVIEW); + editor.apply(); + break; + case 2: + editor.putInt(Helper.SET_VIDEO_MODE, Helper.VIDEO_MODE_DIRECT); + editor.apply(); + break; + } + if( getActivity() != null) + getActivity().recreate(); + Intent intent = new Intent(context, MainActivity.class); + intent.putExtra(INTENT_ACTION, BACK_TO_SETTINGS); + startActivity(intent); + } + count1++; + } + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + return rootView; + } + + + + @Override + public void onCreate(Bundle saveInstance) { + super.onCreate(saveInstance); + } + + + + @Override + public void onAttach(Context context) { + super.onAttach(context); + this.context = context; + } + + +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index f8bdb1d5c..03ed49e62 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -298,6 +298,10 @@ public class Helper { public static final int ATTACHMENT_ASK = 3; + public static final String SET_VIDEO_MODE = "set_video_mode"; + public static final int VIDEO_MODE_TORRENT = 0; + public static final int VIDEO_MODE_WEBVIEW = 1; + public static final int VIDEO_MODE_DIRECT = 2; public static final int BATTERY_PROFILE_NORMAL = 1; public static final int BATTERY_PROFILE_MEDIUM = 2; diff --git a/app/src/main/res/layout/fragment_peertube_settings.xml b/app/src/main/res/layout/fragment_peertube_settings.xml new file mode 100644 index 000000000..9c8ce8469 --- /dev/null +++ b/app/src/main/res/layout/fragment_peertube_settings.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index c6e46d530..66f75bc4d 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -21,8 +21,12 @@ android:id="@+id/swipeContainer" android:paddingLeft="@dimen/drawer_padding" android:paddingRight="@dimen/drawer_padding" + android:layout_marginLeft="@dimen/fab_margin" + android:layout_marginRight="@dimen/fab_margin" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:layout_marginStart="@dimen/fab_margin" + android:layout_marginEnd="@dimen/fab_margin"> + Delete a comment Are you sure to delete this comment? Full screen video + Mode for videos + + + + Torrent + Webview + Direct stream + \ No newline at end of file