Adds fragment for drafts and entry in menu

This commit is contained in:
tom79 2017-09-20 10:04:40 +02:00
parent 1a63539843
commit e961ecbff7
14 changed files with 202 additions and 8 deletions

View File

@ -15,6 +15,9 @@ package fr.gouv.etalab.mastodon.drawers;
* see <http://www.gnu.org/licenses>. */
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -25,10 +28,12 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.List;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
import fr.gouv.etalab.mastodon.helper.Helper;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -48,12 +53,22 @@ public class DraftsListAdapter extends BaseAdapter {
private LayoutInflater layoutInflater;
private Context context;
private DraftsListAdapter draftsListAdapter;
private boolean clickable;
public DraftsListAdapter(Context context, List<StoredStatus> storedStatuses){
this.storedStatuses = storedStatuses;
this.context = context;
layoutInflater = LayoutInflater.from(context);
draftsListAdapter = this;
this.clickable = false;
}
public DraftsListAdapter(Context context, List<StoredStatus> storedStatuses, boolean clickable){
this.storedStatuses = storedStatuses;
this.context = context;
layoutInflater = LayoutInflater.from(context);
draftsListAdapter = this;
this.clickable = clickable;
}
@Override
@ -83,6 +98,7 @@ public class DraftsListAdapter extends BaseAdapter {
holder.draft_title = (TextView) convertView.findViewById(R.id.draft_title);
holder.draft_date = (TextView) convertView.findViewById(R.id.draft_date);
holder.draft_delete = (ImageView) convertView.findViewById(R.id.draft_delete);
holder.drafts_container = (LinearLayout) convertView.findViewById(R.id.drafts_container);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
@ -95,11 +111,20 @@ public class DraftsListAdapter extends BaseAdapter {
changeDrawableColor(context, R.drawable.ic_cancel,R.color.black);
}
final SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
if(draft.getStatus() != null && draft.getStatus().getContent() != null ) {
if (draft.getStatus().getContent().length() > 20)
holder.draft_title.setText(draft.getStatus().getContent().substring(0, 20));
if( this.clickable){
if (draft.getStatus().getContent().length() > 300)
holder.draft_title.setText(draft.getStatus().getContent().substring(0, 299) + "");
else
holder.draft_title.setText(draft.getStatus().getContent());
}else {
if(draft.getStatus() != null && draft.getStatus().getContent() != null ) {
if (draft.getStatus().getContent().length() > 20)
holder.draft_title.setText(draft.getStatus().getContent().substring(0, 20));
else
holder.draft_title.setText(draft.getStatus().getContent());
}
holder.draft_title.setTypeface(Typeface.DEFAULT_BOLD);
}
holder.draft_date.setText(Helper.dateToString(context, draft.getCreation_date()));
holder.draft_delete.setOnClickListener(new View.OnClickListener() {
@ -129,11 +154,24 @@ public class DraftsListAdapter extends BaseAdapter {
.show();
}
});
if( clickable){
holder.drafts_container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentToot = new Intent(context, TootActivity.class);
Bundle b = new Bundle();
b.putLong("restored", draft.getId());
intentToot.putExtras(b);
context.startActivity(intentToot);
}
});
}
return convertView;
}
private class ViewHolder {
LinearLayout drafts_container;
TextView draft_title;
TextView draft_date;
ImageView draft_delete;

View File

@ -0,0 +1,87 @@
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.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.RelativeLayout;
import java.util.List;
import fr.gouv.etalab.mastodon.client.Entities.StoredStatus;
import fr.gouv.etalab.mastodon.drawers.DraftsListAdapter;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import fr.gouv.etalab.mastodon.sqlite.StatusStoredDAO;
import mastodon.etalab.gouv.fr.mastodon.R;
/**
* Created by Thomas on 19/09/2017.
* Fragment to display drafts toots
*/
public class DisplayDraftsFragment extends Fragment {
private Context context;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_drafts, container, false);
context = getContext();
ListView lv_draft_toots = (ListView) rootView.findViewById(R.id.lv_draft_toots);
RelativeLayout mainLoader = (RelativeLayout) rootView.findViewById(R.id.loader);
RelativeLayout textviewNoAction = (RelativeLayout) rootView.findViewById(R.id.no_action);
mainLoader.setVisibility(View.VISIBLE);
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();
final List<StoredStatus> drafts = new StatusStoredDAO(context, db).getAllDrafts();
if( drafts != null && drafts.size() > 0) {
final DraftsListAdapter draftsListAdapter = new DraftsListAdapter(context, drafts, true);
lv_draft_toots.setAdapter(draftsListAdapter);
draftsListAdapter.notifyDataSetChanged();
}else {
textviewNoAction.setVisibility(View.VISIBLE);
}
mainLoader.setVisibility(View.GONE);
return rootView;
}
@Override
public void onCreate(Bundle saveInstance)
{
super.onCreate(saveInstance);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
this.context = context;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 151 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 288 B

View File

@ -19,6 +19,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/drafts_container"
android:layout_marginTop="10dp"
android:orientation="horizontal"
>
@ -27,11 +28,9 @@
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="5dp"
android:id="@+id/account_container"
android:orientation="vertical">
<TextView
android:id="@+id/draft_title"
android:textStyle="bold"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_width="match_parent"

View File

@ -0,0 +1,66 @@
<?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:paddingTop="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/fab_margin"
android:paddingRight="@dimen/fab_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Listview drafts toots -->
<ListView
android:id="@+id/lv_draft_toots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:divider="@null"
>
</ListView>
<RelativeLayout
android:id="@+id/no_action"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/no_action_text"
android:padding="10dp"
android:layout_centerInParent="true"
android:gravity="center"
android:textSize="25sp"
android:layout_gravity="center"
android:textStyle="italic|bold"
android:typeface="serif"
android:text="@string/no_draft"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</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>
</RelativeLayout>

View File

@ -31,6 +31,10 @@
android:id="@+id/nav_scheduled"
android:icon="@drawable/ic_schedule_black"
android:title="@string/scheduled_toots" />
<item
android:id="@+id/nav_drafts"
android:icon="@drawable/ic_mode_edit"
android:title="@string/drafts" />
<item
android:id="@+id/nav_remote_follow"
android:icon="@drawable/ic_remote_follow"

View File

@ -57,7 +57,7 @@
<string name="shared_via">Geteilt von Mastalab</string>
<string name="replies">Antworten</string>
<string name="username">Benutzername</string>
<string name="drafts">Entwürfe</string>
<string name="new_data">Neue Beiträge sind verfügbar! Anzeigen?</string>
<!--- Menu -->
<string name="home_menu">Home</string>

View File

@ -58,7 +58,7 @@
<string name="shared_via">Partagé via Mastalab</string>
<string name="replies">Réponses</string>
<string name="username">Nom d\'utilisateur</string>
<string name="drafts">Brouillons</string>
<string name="new_data">De nouvelles données sont disponibles ! Souhaitez-vous les afficher ?</string>
<!--- Menu -->
<string name="home_menu">Accueil</string>

View File

@ -58,7 +58,7 @@
<string name="shared_via">Shared via Mastalab</string>
<string name="replies">Replies</string>
<string name="username">User name</string>
<string name="drafts">Drafts</string>
<string name="new_data">New data are available! Do you want to display them?</string>
<!--- Menu -->
<string name="home_menu">Home</string>