2019-07-01 18:39:46 +02:00
|
|
|
package app.fedilab.android.fragments;
|
|
|
|
/* Copyright 2019 Thomas Schneider
|
|
|
|
*
|
|
|
|
* This file is a part of Fedilab
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Fedilab 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 Fedilab; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
2019-07-01 19:33:14 +02:00
|
|
|
import android.content.SharedPreferences;
|
2019-07-01 18:39:46 +02:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2019-07-01 19:33:14 +02:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.LinearLayout;
|
2019-07-01 18:39:46 +02:00
|
|
|
|
|
|
|
import androidx.annotation.Nullable;
|
2019-07-01 19:33:14 +02:00
|
|
|
import androidx.core.content.ContextCompat;
|
2019-07-01 18:39:46 +02:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
import app.fedilab.android.R;
|
2019-07-02 17:42:10 +02:00
|
|
|
import app.fedilab.android.animatemenu.interfaces.ScreenShotable;
|
2019-07-01 19:33:14 +02:00
|
|
|
import app.fedilab.android.helper.Helper;
|
2019-07-01 18:39:46 +02:00
|
|
|
|
2019-07-01 19:33:14 +02:00
|
|
|
import static android.content.Context.MODE_PRIVATE;
|
|
|
|
|
2019-07-01 18:39:46 +02:00
|
|
|
public class ContentSettingsFragment extends Fragment implements ScreenShotable {
|
|
|
|
|
|
|
|
|
|
|
|
private View containerView;
|
|
|
|
protected int res;
|
|
|
|
private Bitmap bitmap;
|
2019-07-02 17:42:10 +02:00
|
|
|
private String type;
|
2019-07-01 18:39:46 +02:00
|
|
|
private Context context;
|
|
|
|
public static final String CLOSE = "Close";
|
2019-07-01 19:33:14 +02:00
|
|
|
public static final String TIMELINES = "Timelines";
|
|
|
|
public static final String ADMIN = "Admin";
|
|
|
|
public static final String NOTIFICATIONS = "Notifications";
|
|
|
|
public static final String INTERFACE = "Interface";
|
|
|
|
public static final String COMPOSE = "Compose";
|
|
|
|
public static final String HIDDEN = "Hidden";
|
|
|
|
public static final String TODO = "All";
|
2019-07-01 18:39:46 +02:00
|
|
|
|
|
|
|
public static ContentSettingsFragment newInstance(int resId) {
|
|
|
|
ContentSettingsFragment contentFragment = new ContentSettingsFragment();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putInt(Integer.class.getName(), resId);
|
|
|
|
contentFragment.setArguments(bundle);
|
|
|
|
return contentFragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
|
|
|
context = getContext();
|
|
|
|
assert context != null;
|
|
|
|
this.containerView = view.findViewById(R.id.container);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
assert getArguments() != null;
|
|
|
|
res = getArguments().getInt(Integer.class.getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreateView(@NotNull LayoutInflater inflater, ViewGroup container,
|
|
|
|
Bundle savedInstanceState) {
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_settings_reveal, container, false);
|
2019-07-01 19:33:14 +02:00
|
|
|
FrameLayout containerFrame = rootView.findViewById(R.id.container);
|
|
|
|
|
2019-07-02 17:42:10 +02:00
|
|
|
Bundle bundle = this.getArguments();
|
|
|
|
if (bundle != null) {
|
|
|
|
type = bundle.getString("type", null);
|
|
|
|
}
|
2019-07-01 19:33:14 +02:00
|
|
|
|
|
|
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
switch (theme){
|
|
|
|
case Helper.THEME_LIGHT:
|
|
|
|
containerFrame.setBackgroundColor(ContextCompat.getColor(context, R.color.white));
|
|
|
|
break;
|
|
|
|
case Helper.THEME_DARK:
|
|
|
|
containerFrame.setBackgroundColor(ContextCompat.getColor(context, R.color.mastodonC1));
|
|
|
|
break;
|
|
|
|
case Helper.THEME_BLACK:
|
|
|
|
containerFrame.setBackgroundColor(ContextCompat.getColor(context, R.color.black));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
containerFrame.setBackgroundColor(ContextCompat.getColor(context, R.color.mastodonC1));
|
|
|
|
}
|
|
|
|
LinearLayout settings_timeline = rootView.findViewById(R.id.settings_timeline);
|
|
|
|
LinearLayout settings_notifications = rootView.findViewById(R.id.settings_notifications);
|
|
|
|
LinearLayout settings_admin = rootView.findViewById(R.id.settings_admin);
|
|
|
|
LinearLayout settings_interface = rootView.findViewById(R.id.settings_interface);
|
|
|
|
LinearLayout settings_compose = rootView.findViewById(R.id.settings_compose);
|
|
|
|
LinearLayout settings_hidden = rootView.findViewById(R.id.settings_hidden);
|
|
|
|
LinearLayout settings_to_do = rootView.findViewById(R.id.settings_to_do);
|
2019-07-01 18:39:46 +02:00
|
|
|
|
2019-07-02 17:42:10 +02:00
|
|
|
if(type == null || type.equals(TIMELINES)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_timeline.setVisibility(View.VISIBLE);
|
2019-07-02 17:42:10 +02:00
|
|
|
}else if( type.equals(NOTIFICATIONS)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_notifications.setVisibility(View.VISIBLE);
|
2019-07-02 17:42:10 +02:00
|
|
|
}else if( type.equals(ADMIN)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_admin.setVisibility(View.VISIBLE);
|
2019-07-02 17:42:10 +02:00
|
|
|
}else if(type.equals(INTERFACE)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_interface.setVisibility(View.VISIBLE);
|
2019-07-02 17:42:10 +02:00
|
|
|
}else if(type.equals(COMPOSE)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_compose.setVisibility(View.VISIBLE);
|
2019-07-02 17:42:10 +02:00
|
|
|
}else if( type.equals(HIDDEN)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_hidden.setVisibility(View.VISIBLE);
|
2019-07-02 17:42:10 +02:00
|
|
|
}else if( type.equals(TODO)){
|
2019-07-01 19:33:14 +02:00
|
|
|
settings_to_do.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-07-01 18:39:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void takeScreenShot() {
|
|
|
|
Thread thread = new Thread() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
Bitmap bitmap = Bitmap.createBitmap(containerView.getWidth(),
|
|
|
|
containerView.getHeight(), Bitmap.Config.ARGB_8888);
|
|
|
|
Canvas canvas = new Canvas(bitmap);
|
|
|
|
containerView.draw(canvas);
|
|
|
|
ContentSettingsFragment.this.bitmap = bitmap;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
thread.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Bitmap getBitmap() {
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
}
|