List activity
This commit is contained in:
parent
aa8e3aa630
commit
c7fe26167d
|
@ -138,6 +138,11 @@
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
/>
|
/>
|
||||||
|
<activity android:name=".activities.ListActivity"
|
||||||
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
|
android:configChanges="orientation|screenSize"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
/>
|
||||||
<activity android:name=".activities.ShowConversationActivity"
|
<activity android:name=".activities.ShowConversationActivity"
|
||||||
android:windowSoftInputMode="stateAlwaysHidden"
|
android:windowSoftInputMode="stateAlwaysHidden"
|
||||||
android:configChanges="orientation|screenSize"
|
android:configChanges="orientation|screenSize"
|
||||||
|
|
|
@ -1273,7 +1273,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
||||||
}else{
|
}else{
|
||||||
delete_all.setVisibility(View.VISIBLE);
|
delete_all.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
if( id != R.id.nav_search){
|
if( id != R.id.nav_search && id != R.id.nav_list){
|
||||||
add_new.setVisibility(View.GONE);
|
add_new.setVisibility(View.GONE);
|
||||||
}else{
|
}else{
|
||||||
add_new.setVisibility(View.VISIBLE);
|
add_new.setVisibility(View.VISIBLE);
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* 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>. */
|
||||||
|
package fr.gouv.etalab.mastodon.activities;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
|
||||||
|
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.helper.Helper;
|
||||||
|
import fr.gouv.etalab.mastodon.interfaces.OnListActionInterface;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Thomas on 14/12/2017.
|
||||||
|
* Display content of a list, also help to manage it
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ListActivity extends BaseActivity implements OnListActionInterface {
|
||||||
|
|
||||||
|
|
||||||
|
private RecyclerView lv_status;
|
||||||
|
private RelativeLayout loader;
|
||||||
|
private String title, listId;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
|
||||||
|
if( theme == Helper.THEME_LIGHT){
|
||||||
|
setTheme(R.style.AppTheme);
|
||||||
|
}else {
|
||||||
|
setTheme(R.style.AppThemeDark);
|
||||||
|
}
|
||||||
|
setContentView(R.layout.activity_list);
|
||||||
|
|
||||||
|
loader = findViewById(R.id.loader);
|
||||||
|
lv_status = findViewById(R.id.lv_status);
|
||||||
|
|
||||||
|
Bundle b = getIntent().getExtras();
|
||||||
|
if(b != null){
|
||||||
|
title = b.getString("title");
|
||||||
|
listId = b.getString("id");
|
||||||
|
}else{
|
||||||
|
Toast.makeText(this,R.string.toast_error_search,Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
if( getSupportActionBar() != null)
|
||||||
|
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
setTitle(title);
|
||||||
|
loader.setVisibility(View.VISIBLE);
|
||||||
|
lv_status.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case android.R.id.home:
|
||||||
|
finish();
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActionDone(ManageListsAsyncTask.action actionType, APIResponse apiResponse, int statusCode) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,8 +17,10 @@ package fr.gouv.etalab.mastodon.drawers;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -31,6 +33,7 @@ import android.widget.TextView;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
|
import fr.gouv.etalab.mastodon.activities.ListActivity;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||||
|
|
||||||
|
@ -100,10 +103,14 @@ public class ListAdapter extends BaseAdapter {
|
||||||
holder.search_container.setOnClickListener(new View.OnClickListener() {
|
holder.search_container.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(context, ListActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString("id", list.getId());
|
||||||
|
b.putString("title", list.getTitle());
|
||||||
|
intent.putExtras(b);
|
||||||
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
|
||||||
|
|
||||||
holder.search_container.setOnLongClickListener(new View.OnLongClickListener() {
|
holder.search_container.setOnLongClickListener(new View.OnLongClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.fragments;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -40,6 +41,8 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import fr.gouv.etalab.mastodon.R;
|
import fr.gouv.etalab.mastodon.R;
|
||||||
|
import fr.gouv.etalab.mastodon.activities.ListActivity;
|
||||||
|
import fr.gouv.etalab.mastodon.activities.MainActivity;
|
||||||
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
import fr.gouv.etalab.mastodon.asynctasks.ManageListsAsyncTask;
|
||||||
import fr.gouv.etalab.mastodon.client.APIResponse;
|
import fr.gouv.etalab.mastodon.client.APIResponse;
|
||||||
import fr.gouv.etalab.mastodon.drawers.ListAdapter;
|
import fr.gouv.etalab.mastodon.drawers.ListAdapter;
|
||||||
|
@ -65,6 +68,7 @@ public class DisplayListsFragment extends Fragment implements OnListActionInterf
|
||||||
private ListView lv_lists;
|
private ListView lv_lists;
|
||||||
private RelativeLayout textviewNoAction;
|
private RelativeLayout textviewNoAction;
|
||||||
private FloatingActionButton add_new;
|
private FloatingActionButton add_new;
|
||||||
|
private ListAdapter listAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -81,12 +85,17 @@ public class DisplayListsFragment extends Fragment implements OnListActionInterf
|
||||||
no_action_text = rootView.findViewById(R.id.no_action_text);
|
no_action_text = rootView.findViewById(R.id.no_action_text);
|
||||||
mainLoader = rootView.findViewById(R.id.loader);
|
mainLoader = rootView.findViewById(R.id.loader);
|
||||||
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
|
RelativeLayout nextElementLoader = rootView.findViewById(R.id.loading_next_items);
|
||||||
add_new = rootView.findViewById(R.id.add_new);
|
|
||||||
mainLoader.setVisibility(View.VISIBLE);
|
mainLoader.setVisibility(View.VISIBLE);
|
||||||
nextElementLoader.setVisibility(View.GONE);
|
nextElementLoader.setVisibility(View.GONE);
|
||||||
|
lists = new ArrayList<>();
|
||||||
|
listAdapter = new ListAdapter(context, lists, textviewNoAction);
|
||||||
|
lv_lists.setAdapter(listAdapter);
|
||||||
no_action_text.setVisibility(View.GONE);
|
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);
|
asyncTask = new ManageListsAsyncTask(context, ManageListsAsyncTask.action.GET_LIST, null, null, null, null, DisplayListsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
try {
|
||||||
|
add_new = ((MainActivity) context).findViewById(R.id.add_new);
|
||||||
|
}catch (Exception ignored){}
|
||||||
|
if( add_new != null)
|
||||||
add_new.setOnClickListener(new View.OnClickListener() {
|
add_new.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -111,6 +120,8 @@ public class DisplayListsFragment extends Fragment implements OnListActionInterf
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
AlertDialog alertDialog = dialogBuilder.create();
|
AlertDialog alertDialog = dialogBuilder.create();
|
||||||
alertDialog.setTitle(getString(R.string.action_lists_create));
|
alertDialog.setTitle(getString(R.string.action_lists_create));
|
||||||
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
|
@ -165,17 +176,27 @@ public class DisplayListsFragment extends Fragment implements OnListActionInterf
|
||||||
}
|
}
|
||||||
if( actionType == ManageListsAsyncTask.action.GET_LIST) {
|
if( actionType == ManageListsAsyncTask.action.GET_LIST) {
|
||||||
if (apiResponse.getLists() != null && apiResponse.getLists().size() > 0) {
|
if (apiResponse.getLists() != null && apiResponse.getLists().size() > 0) {
|
||||||
;
|
|
||||||
this.lists = new ArrayList<>();
|
|
||||||
this.lists.addAll(apiResponse.getLists());
|
this.lists.addAll(apiResponse.getLists());
|
||||||
ListAdapter listAdapter = new ListAdapter(context, this.lists, textviewNoAction);
|
listAdapter.notifyDataSetChanged();
|
||||||
lv_lists.setAdapter(listAdapter);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
no_action_text.setVisibility(View.VISIBLE);
|
no_action_text.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}else if( actionType == ManageListsAsyncTask.action.CREATE_LIST){
|
}else if( actionType == ManageListsAsyncTask.action.CREATE_LIST){
|
||||||
|
if (apiResponse.getLists() != null && apiResponse.getLists().size() > 0) {
|
||||||
|
String listId = apiResponse.getLists().get(0).getId();
|
||||||
|
String title = apiResponse.getLists().get(0).getTitle();
|
||||||
|
Intent intent = new Intent(context, ListActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString("id", listId);
|
||||||
|
b.putString("title", title);
|
||||||
|
intent.putExtras(b);
|
||||||
|
context.startActivity(intent);
|
||||||
|
this.lists.add(0, apiResponse.getLists().get(0));
|
||||||
|
listAdapter.notifyDataSetChanged();
|
||||||
|
}else{
|
||||||
|
Toast.makeText(context, apiResponse.getError().getError(),Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
<?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:paddingTop="@dimen/activity_vertical_margin"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<!-- Listview status -->
|
||||||
|
<android.support.v4.widget.SwipeRefreshLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:id="@+id/swipeContainer"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
<android.support.v7.widget.RecyclerView
|
||||||
|
android:id="@+id/lv_status"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="none"
|
||||||
|
/>
|
||||||
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/no_action"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:padding="10dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:textSize="25sp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:textStyle="italic|bold"
|
||||||
|
android:typeface="serif"
|
||||||
|
android:text="@string/no_status"
|
||||||
|
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 status -->
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/loading_next_status"
|
||||||
|
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>
|
|
@ -73,13 +73,5 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:indeterminate="true" />
|
android:indeterminate="true" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
<android.support.design.widget.FloatingActionButton
|
|
||||||
android:id="@+id/add_new"
|
|
||||||
android:visibility="gone"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom|end"
|
|
||||||
android:layout_margin="@dimen/fab_margin"
|
|
||||||
app:srcCompat="@drawable/ic_action_add_new"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue