Adds List in menu
This commit is contained in:
parent
25410f5061
commit
c4d05e1191
|
@ -49,7 +49,6 @@ import android.support.design.widget.NavigationView;
|
|||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuItem;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -82,6 +81,7 @@ import fr.gouv.etalab.mastodon.client.Entities.Version;
|
|||
import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayDraftsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayFollowRequestSentFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayListsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayNotificationsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplayScheduledTootsFragment;
|
||||
import fr.gouv.etalab.mastodon.fragments.DisplaySearchFragment;
|
||||
|
@ -752,6 +752,19 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
navigationView.getMenu().findItem(R.id.nav_follow_request).setVisible(false);
|
||||
}
|
||||
|
||||
//Check instance release for lists
|
||||
String instance = Helper.getLiveInstance(getApplicationContext());
|
||||
String instanceVersion = sharedpreferences.getString(Helper.INSTANCE_VERSION + userId + instance, null);
|
||||
if (instanceVersion != null) {
|
||||
Version currentVersion = new Version(instanceVersion);
|
||||
Version minVersion = new Version("2.1");
|
||||
if (currentVersion.compareTo(minVersion) == 1 || currentVersion.equals(minVersion)) {
|
||||
navigationView.getMenu().findItem(R.id.nav_list).setVisible(true);
|
||||
} else {
|
||||
navigationView.getMenu().findItem(R.id.nav_list).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
LinearLayout owner_container = headerLayout.findViewById(R.id.main_header_container);
|
||||
owner_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -1320,6 +1333,12 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
fragmentTag = "FOLLOW_REQUEST_SENT";
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, followRequestSentFragment, fragmentTag).commit();
|
||||
}else if(id == R.id.nav_list){
|
||||
toot.setVisibility(View.GONE);
|
||||
DisplayListsFragment displayListsFragment = new DisplayListsFragment();
|
||||
fragmentTag = "LISTS";
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, displayListsFragment, fragmentTag).commit();
|
||||
}
|
||||
|
||||
populateTitleWithTag(fragmentTag, item.getTitle().toString(), item.getItemId());
|
||||
|
|
|
@ -1075,13 +1075,24 @@ public class API {
|
|||
return results;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves Accounts when searching (ie: via @...) *synchronously*
|
||||
* Not limited to following
|
||||
* @param query String search
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse searchAccounts(String query, int count) {
|
||||
return searchAccounts(query, count, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Accounts when searching (ie: via @...) *synchronously*
|
||||
*
|
||||
* @param query String search
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse searchAccounts(String query, int count) {
|
||||
public APIResponse searchAccounts(String query, int count, boolean following) {
|
||||
|
||||
HashMap<String, String> params = new HashMap<>();
|
||||
params.put("q", query);
|
||||
|
@ -1089,6 +1100,8 @@ public class API {
|
|||
count = 5;
|
||||
if( count > 40 )
|
||||
count = 40;
|
||||
if( following)
|
||||
params.put("following", Boolean.toString(true));
|
||||
params.put("limit", String.valueOf(count));
|
||||
|
||||
try {
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
package fr.gouv.etalab.mastodon.drawers;
|
||||
/* 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>. */
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 13/12/2017.
|
||||
* Adapter for lists
|
||||
*/
|
||||
public class ListAdapter extends BaseAdapter {
|
||||
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.List> lists;
|
||||
private LayoutInflater layoutInflater;
|
||||
private Context context;
|
||||
private ListAdapter listAdapter;
|
||||
private RelativeLayout textviewNoAction;
|
||||
|
||||
public ListAdapter(Context context, List<fr.gouv.etalab.mastodon.client.Entities.List> lists, RelativeLayout textviewNoAction){
|
||||
this.lists = lists;
|
||||
layoutInflater = LayoutInflater.from(context);
|
||||
this.context = context;
|
||||
this.listAdapter = this;
|
||||
this.textviewNoAction = textviewNoAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return lists.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return lists.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
|
||||
final fr.gouv.etalab.mastodon.client.Entities.List list = lists.get(position);
|
||||
final ViewHolder holder;
|
||||
if (convertView == null) {
|
||||
convertView = layoutInflater.inflate(R.layout.drawer_search, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.search_title = convertView.findViewById(R.id.search_keyword);
|
||||
holder.search_container = convertView.findViewById(R.id.search_container);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||
if( theme == Helper.THEME_LIGHT){
|
||||
holder.search_container.setBackgroundResource(R.color.mastodonC3__);
|
||||
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.black);
|
||||
}else {
|
||||
holder.search_container.setBackgroundResource(R.color.mastodonC1_);
|
||||
changeDrawableColor(context, R.drawable.ic_keyboard_arrow_right,R.color.dark_text);
|
||||
}
|
||||
holder.search_title.setText(list.getTitle());
|
||||
holder.search_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
||||
holder.search_container.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(context.getString(R.string.action_lists_delete) + ": " + list.getTitle());
|
||||
builder.setMessage(context.getString(R.string.action_lists_confirm_delete) );
|
||||
builder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
lists.remove(list);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
if( lists.size() == 0 && textviewNoAction != null && textviewNoAction.getVisibility() == View.GONE)
|
||||
textviewNoAction.setVisibility(View.VISIBLE);
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
return convertView;
|
||||
}
|
||||
|
||||
|
||||
private class ViewHolder {
|
||||
LinearLayout search_container;
|
||||
TextView search_title;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
package fr.gouv.etalab.mastodon.fragments;
|
||||
/* 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>. */
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
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.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.gouv.etalab.mastodon.R;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||
import fr.gouv.etalab.mastodon.drawers.ListAdapter;
|
||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Thomas on 13/12/2017.
|
||||
* Fragment to display Lists
|
||||
*/
|
||||
public class DisplayListsFragment extends Fragment implements OnListActionInterface {
|
||||
|
||||
|
||||
private Context context;
|
||||
private AsyncTask<Void, Void, Void> asyncTask;
|
||||
private ListAdapter listAdapter;
|
||||
private List<fr.gouv.etalab.mastodon.client.Entities.List> lists;
|
||||
private TextView no_action_text;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
//View for fragment is the same that fragment accounts
|
||||
View rootView = inflater.inflate(R.layout.fragment_list, container, false);
|
||||
|
||||
context = getContext();
|
||||
lists = new ArrayList<>();
|
||||
|
||||
|
||||
ListView lv_lists = rootView.findViewById(R.id.lv_lists);
|
||||
no_action_text = rootView.findViewById(R.id.no_action_text);
|
||||
RelativeLayout mainLoader = rootView.findViewById(R.id.loader);
|
||||
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
|
||||
RelativeLayout textviewNoAction = rootView.findViewById(R.id.no_action);
|
||||
mainLoader.setVisibility(View.VISIBLE);
|
||||
nextElementLoader.setVisibility(View.GONE);
|
||||
listAdapter = new ListAdapter(context, this.lists, textviewNoAction);
|
||||
lv_lists.setAdapter(listAdapter);
|
||||
|
||||
no_action_text.setVisibility(View.GONE);
|
||||
asyncTask = new ManageListsAsyncTask(context, ManageListsAsyncTask.action.GET_LIST, null, null, null, null, DisplayListsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle saveInstance)
|
||||
{
|
||||
super.onCreate(saveInstance);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
|
||||
asyncTask.cancel(true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActionDone(APIResponse apiResponse, int statusCode) {
|
||||
if( apiResponse.getError() != null){
|
||||
final SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
boolean show_error_messages = sharedpreferences.getBoolean(Helper.SET_SHOW_ERROR_MESSAGES, true);
|
||||
if( show_error_messages)
|
||||
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if( this.lists != null && this.lists.size() > 0) {
|
||||
this.lists = apiResponse.getLists();
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}else {
|
||||
no_action_text.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
|
||||
</vector>
|
|
@ -0,0 +1,77 @@
|
|||
<?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>.
|
||||
-->
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:paddingLeft="@dimen/fab_margin"
|
||||
android:paddingRight="@dimen/fab_margin"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<!-- Listview list -->
|
||||
<ListView
|
||||
android:id="@+id/lv_lists"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none"
|
||||
android:divider="@null"
|
||||
/>
|
||||
<RelativeLayout
|
||||
android:id="@+id/no_action"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<TextView
|
||||
android:id="@+id/no_action_text"
|
||||
android:padding="10dp"
|
||||
android:gravity="center"
|
||||
android:textSize="25sp"
|
||||
android:layout_gravity="center"
|
||||
android:textStyle="italic|bold"
|
||||
android:typeface="serif"
|
||||
android:text="@string/action_lists_empty_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</RelativeLayout>
|
||||
<!-- Main Loader -->
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/loader"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
>
|
||||
<ProgressBar
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
<!-- Loader for next items -->
|
||||
<RelativeLayout
|
||||
android:id="@+id/loading_next_items"
|
||||
android:visibility="gone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:gravity="bottom|center_horizontal"
|
||||
android:layout_height="20dp">
|
||||
<ProgressBar
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:indeterminate="true" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
@ -11,6 +11,10 @@
|
|||
android:id="@+id/menu_none"
|
||||
android:title=""
|
||||
android:visible="false"/>
|
||||
<item
|
||||
android:id="@+id/nav_list"
|
||||
android:icon="@drawable/ic_list"
|
||||
android:title="@string/action_lists" />
|
||||
<item
|
||||
android:id="@+id/nav_scheduled"
|
||||
android:icon="@drawable/ic_schedule"
|
||||
|
|
Loading…
Reference in New Issue