2019-05-18 11:10:30 +02:00
|
|
|
package app.fedilab.android.fragments;
|
2017-09-20 10:04:40 +02:00
|
|
|
/* Copyright 2017 Thomas Schneider
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* This file is a part of Fedilab
|
2017-09-20 10:04:40 +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.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-09-20 10:04:40 +02:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
|
|
|
*
|
2019-05-18 11:10:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
2017-09-20 10:04:40 +02:00
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-10-30 07:54:02 +01:00
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.SharedPreferences;
|
2017-09-20 10:04:40 +02:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
|
|
|
import android.os.Bundle;
|
2019-06-11 19:38:26 +02:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2017-09-20 10:04:40 +02:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.RelativeLayout;
|
2017-10-30 07:54:02 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2017-09-20 10:04:40 +02:00
|
|
|
import java.util.List;
|
2017-09-20 14:51:15 +02:00
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import app.fedilab.android.client.Entities.StoredStatus;
|
|
|
|
import app.fedilab.android.drawers.DraftsListAdapter;
|
|
|
|
import app.fedilab.android.helper.Helper;
|
|
|
|
import app.fedilab.android.sqlite.Sqlite;
|
|
|
|
import app.fedilab.android.sqlite.StatusStoredDAO;
|
|
|
|
import app.fedilab.android.activities.MainActivity;
|
|
|
|
import app.fedilab.android.R;
|
2017-09-20 10:04:40 +02:00
|
|
|
|
2019-05-18 11:10:30 +02:00
|
|
|
import static app.fedilab.android.helper.Helper.changeDrawableColor;
|
2017-10-30 07:54:02 +01:00
|
|
|
|
2017-09-20 10:04:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Thomas on 19/09/2017.
|
|
|
|
* Fragment to display drafts toots
|
|
|
|
*/
|
|
|
|
public class DisplayDraftsFragment extends Fragment {
|
|
|
|
|
|
|
|
|
|
|
|
private Context context;
|
2017-10-30 07:54:02 +01:00
|
|
|
private List<StoredStatus> drafts;
|
|
|
|
private DraftsListAdapter draftsListAdapter;
|
|
|
|
private RelativeLayout textviewNoAction;
|
2017-09-20 10:04:40 +02:00
|
|
|
@Override
|
2017-12-15 18:03:06 +01:00
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
2017-09-20 10:04:40 +02:00
|
|
|
|
|
|
|
View rootView = inflater.inflate(R.layout.fragment_drafts, container, false);
|
|
|
|
context = getContext();
|
|
|
|
|
2017-10-30 07:54:02 +01:00
|
|
|
final ListView lv_draft_toots = rootView.findViewById(R.id.lv_draft_toots);
|
2017-09-20 10:04:40 +02:00
|
|
|
|
2017-10-28 11:02:37 +02:00
|
|
|
RelativeLayout mainLoader = rootView.findViewById(R.id.loader);
|
2017-10-30 07:54:02 +01:00
|
|
|
textviewNoAction = rootView.findViewById(R.id.no_action);
|
2017-09-20 10:04:40 +02:00
|
|
|
mainLoader.setVisibility(View.VISIBLE);
|
2017-10-30 07:54:02 +01:00
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
if( theme == Helper.THEME_DARK){
|
2019-05-18 11:10:30 +02:00
|
|
|
Helper.changeDrawableColor(context, R.drawable.ic_cancel,R.color.dark_text);
|
2017-10-30 07:54:02 +01:00
|
|
|
}else {
|
2019-05-18 11:10:30 +02:00
|
|
|
Helper.changeDrawableColor(context, R.drawable.ic_cancel,R.color.black);
|
2017-10-30 07:54:02 +01:00
|
|
|
}
|
2017-09-20 10:04:40 +02:00
|
|
|
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
|
|
//Removes all scheduled toots that have sent
|
|
|
|
new StatusStoredDAO(context, db).removeAllSent();
|
2017-10-30 07:54:02 +01:00
|
|
|
drafts = new StatusStoredDAO(context, db).getAllDrafts();
|
2017-09-20 10:04:40 +02:00
|
|
|
if( drafts != null && drafts.size() > 0) {
|
2017-11-24 15:34:55 +01:00
|
|
|
draftsListAdapter = new DraftsListAdapter(context, drafts, true, textviewNoAction);
|
2017-09-20 10:04:40 +02:00
|
|
|
lv_draft_toots.setAdapter(draftsListAdapter);
|
|
|
|
draftsListAdapter.notifyDataSetChanged();
|
|
|
|
}else {
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
mainLoader.setVisibility(View.GONE);
|
2017-10-30 07:54:02 +01:00
|
|
|
FloatingActionButton delete_all = null;
|
|
|
|
try {
|
|
|
|
delete_all = ((MainActivity) context).findViewById(R.id.delete_all);
|
|
|
|
}catch (Exception ignored){}
|
|
|
|
if( delete_all != null)
|
|
|
|
delete_all.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
2018-11-03 14:45:55 +01:00
|
|
|
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
|
|
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
|
|
|
int style;
|
|
|
|
if (theme == Helper.THEME_DARK) {
|
|
|
|
style = R.style.DialogDark;
|
|
|
|
} else if (theme == Helper.THEME_BLACK){
|
|
|
|
style = R.style.DialogBlack;
|
|
|
|
}else {
|
|
|
|
style = R.style.Dialog;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(context, style);
|
2017-10-30 07:54:02 +01:00
|
|
|
builder.setTitle(R.string.delete_all);
|
|
|
|
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
|
|
|
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogConfirm, int which) {
|
|
|
|
new StatusStoredDAO(context, db).removeAllDrafts();
|
|
|
|
drafts = new ArrayList<>();
|
|
|
|
drafts.clear();
|
2017-11-24 15:34:55 +01:00
|
|
|
draftsListAdapter = new DraftsListAdapter(context, drafts, true, textviewNoAction);
|
2017-10-30 07:54:02 +01:00
|
|
|
lv_draft_toots.setAdapter(draftsListAdapter);
|
|
|
|
draftsListAdapter.notifyDataSetChanged();
|
|
|
|
textviewNoAction.setVisibility(View.VISIBLE);
|
|
|
|
dialogConfirm.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogConfirm, int which) {
|
|
|
|
dialogConfirm.dismiss();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
}
|
|
|
|
});
|
2017-09-20 10:04:40 +02:00
|
|
|
return rootView;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle saveInstance)
|
|
|
|
{
|
|
|
|
super.onCreate(saveInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAttach(Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|