Adds filter dialog
This commit is contained in:
parent
504e3c0146
commit
87d244be1b
|
@ -16,6 +16,8 @@ package fr.gouv.etalab.mastodon.activities;
|
|||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
@ -26,6 +28,7 @@ import android.os.Bundle;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -36,6 +39,8 @@ import android.view.Menu;
|
|||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
@ -45,6 +50,8 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
|||
import com.bumptech.glide.request.transition.Transition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
|
||||
|
@ -55,9 +62,9 @@ import fr.gouv.etalab.mastodon.drawers.StatusListAdapter;
|
|||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnRetrieveFeedsInterface;
|
||||
import fr.gouv.etalab.mastodon.services.BackupStatusInDataBaseService;
|
||||
import fr.gouv.etalab.mastodon.services.BackupStatusService;
|
||||
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
import fr.gouv.etalab.mastodon.sqlite.StatusCacheDAO;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -82,6 +89,8 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
private boolean swiped;
|
||||
private boolean flag_loading;
|
||||
LinearLayoutManager mLayoutManager;
|
||||
private int style;
|
||||
private Button settings_time_from, settings_time_to;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -139,6 +148,13 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
mLayoutManager = new LinearLayoutManager(OwnerStatusActivity.this);
|
||||
lv_status.setLayoutManager(mLayoutManager);
|
||||
|
||||
|
||||
if( theme == Helper.THEME_DARK){
|
||||
style = R.style.DialogDark;
|
||||
}else {
|
||||
style = R.style.Dialog;
|
||||
}
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Account account = new AccountDAO(OwnerStatusActivity.this,db).getAccountByID(userId);
|
||||
String url = account.getAvatar();
|
||||
|
@ -206,6 +222,28 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
return true;
|
||||
}
|
||||
|
||||
private DatePickerDialog.OnDateSetListener iniDateSetListener =
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
|
||||
public void onDateSet(DatePicker view, int year,
|
||||
int monthOfYear, int dayOfMonth) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(year, monthOfYear, dayOfMonth, 0, 0);
|
||||
settings_time_from.setText(Helper.shortDateToString(new Date(c.getTimeInMillis())));
|
||||
}
|
||||
|
||||
};
|
||||
private DatePickerDialog.OnDateSetListener endDateSetListener =
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
|
||||
public void onDateSet(DatePicker view, int year,
|
||||
int monthOfYear, int dayOfMonth) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(year, monthOfYear, dayOfMonth, 23, 59);
|
||||
settings_time_to.setText(Helper.shortDateToString(new Date(c.getTimeInMillis())));
|
||||
}
|
||||
|
||||
};
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
|
@ -217,6 +255,68 @@ public class OwnerStatusActivity extends BaseActivity implements OnRetrieveFeeds
|
|||
startService(backupIntent);
|
||||
return true;
|
||||
case R.id.action_filter:
|
||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OwnerStatusActivity.this);
|
||||
LayoutInflater inflater = this.getLayoutInflater();
|
||||
@SuppressLint("InflateParams") View dialogView = inflater.inflate(R.layout.filter_owner_toots, null);
|
||||
dialogBuilder.setView(dialogView);
|
||||
dialogBuilder
|
||||
.setTitle(R.string.action_filter)
|
||||
.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
final AlertDialog alertDialog = dialogBuilder.create();
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(OwnerStatusActivity.this, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
Date dateInit = new StatusCacheDAO(OwnerStatusActivity.this, db).getSmallerDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
Date dateEnd = new StatusCacheDAO(OwnerStatusActivity.this, db).getGreaterDate(StatusCacheDAO.ARCHIVE_CACHE);
|
||||
String dateInitString = Helper.shortDateToString(dateInit);
|
||||
String dateEndString = Helper.shortDateToString(dateEnd);
|
||||
|
||||
settings_time_from = dialogView.findViewById(R.id.settings_time_from);
|
||||
settings_time_to = dialogView.findViewById(R.id.settings_time_to);
|
||||
|
||||
settings_time_from.setText(dateInitString);
|
||||
settings_time_to.setText(dateEndString);
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(dateInit);
|
||||
int yearIni = c.get(Calendar.YEAR);
|
||||
int monthIni = c.get(Calendar.MONTH);
|
||||
int dayIni = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
final DatePickerDialog dateIniPickerDialog = new DatePickerDialog(
|
||||
OwnerStatusActivity.this, style, iniDateSetListener, yearIni, monthIni, dayIni);
|
||||
settings_time_from.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dateIniPickerDialog.show();
|
||||
}
|
||||
});
|
||||
Calendar ce = Calendar.getInstance();
|
||||
c.setTime(dateEnd);
|
||||
int yearEnd = ce.get(Calendar.YEAR);
|
||||
int monthEnd = ce.get(Calendar.MONTH);
|
||||
int dayEnd = ce.get(Calendar.DAY_OF_MONTH);
|
||||
final DatePickerDialog dateEndPickerDialog = new DatePickerDialog(
|
||||
OwnerStatusActivity.this, style, endDateSetListener, yearEnd, monthEnd, dayEnd);
|
||||
settings_time_to.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dateEndPickerDialog.show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
alertDialog.show();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
|
@ -483,6 +483,16 @@ public class Helper {
|
|||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date in String -> format yyyy-MM-dd HH:mm:ss
|
||||
* @param date Date
|
||||
* @return String
|
||||
*/
|
||||
public static String shortDateToString(Date date) {
|
||||
SimpleDateFormat df = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a date in String -> format yyyy-MM-dd HH:mm:ss
|
||||
* @param context Context
|
||||
|
|
|
@ -203,6 +203,51 @@ public class StatusCacheDAO {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller date
|
||||
* @return Date
|
||||
*/
|
||||
public Date getSmallerDate(int cacheType){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_CACHED_ACTION + " = '" + cacheType+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_CREATED_AT + " ASC", "1");
|
||||
//No element found
|
||||
if (c.getCount() == 0)
|
||||
return null;
|
||||
//Take the first element
|
||||
c.moveToFirst();
|
||||
String date = c.getString(c.getColumnIndex(Sqlite.COL_CREATED_AT));
|
||||
c.close();
|
||||
return Helper.stringToDate(context, date);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smaller date
|
||||
* @return Date
|
||||
*/
|
||||
public Date getGreaterDate(int cacheType){
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = Helper.getLiveInstance(context);
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_STATUSES_CACHE, null, Sqlite.COL_CACHED_ACTION + " = '" + cacheType+ "' AND " + Sqlite.COL_INSTANCE + " = '" + instance+ "' AND " + Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_CREATED_AT + " DESC", "1");
|
||||
//No element found
|
||||
if (c.getCount() == 0)
|
||||
return null;
|
||||
//Take the first element
|
||||
c.moveToFirst();
|
||||
String date = c.getString(c.getColumnIndex(Sqlite.COL_CREATED_AT));
|
||||
c.close();
|
||||
return Helper.stringToDate(context, date);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last id of backup for a user depending of the type of cache
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2017 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 <http://www.gnu.org/licenses>.
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:paddingStart="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_vertical_margin"
|
||||
android:paddingEnd="@dimen/activity_vertical_margin"
|
||||
android:paddingRight="@dimen/activity_vertical_margin"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
style="?attr/shapeBorder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="10dp"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:text="@string/settings_time_from"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:focusableInTouchMode="false"
|
||||
android:id="@+id/settings_time_from"
|
||||
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:text="@string/settings_time_to"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<Button
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:focusableInTouchMode="false"
|
||||
style="@style/Base.Widget.AppCompat.Button.Borderless.Colored"
|
||||
android:id="@+id/settings_time_to"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/filter_visibility_public"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/v_public"
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/filter_visibility_unlisted"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/v_unlisted"
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/filter_visibility_private"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/v_private"
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/filter_visibility_direct"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/v_direct"
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content" />
|
||||
<CheckBox
|
||||
android:id="@+id/filter_boost"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/show_boosts"
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content" />
|
||||
<CheckBox
|
||||
android:id="@+id/filer_reply"
|
||||
android:layout_width="wrap_content"
|
||||
android:text="@string/show_replies"
|
||||
android:checked="true"
|
||||
android:layout_height="wrap_content" />
|
||||
<EditText
|
||||
android:inputType="text"
|
||||
android:id="@+id/filter_keywords"
|
||||
android:maxLines="2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
|
@ -401,6 +401,11 @@
|
|||
<string name="action_sync">Synchronize</string>
|
||||
<string name="action_filter">Filter</string>
|
||||
<string name="owner_cached_toots">Your toots</string>
|
||||
<string name="v_public">Public</string>
|
||||
<string name="v_unlisted">Unlisted</string>
|
||||
<string name="v_private">Private</string>
|
||||
<string name="v_direct">Direct</string>
|
||||
|
||||
<string name="owner_cached_toots_empty">No toots were found in database. Please, use the synchronize button from the menu to retrieve them.</string>
|
||||
<!-- PRIVACY -->
|
||||
<string name="privacy_data_title">Recorded data</string>
|
||||
|
|
Loading…
Reference in New Issue