From e961ecbff7542d86d45106e2e7020eb381ab4748 Mon Sep 17 00:00:00 2001 From: tom79 Date: Wed, 20 Sep 2017 10:04:40 +0200 Subject: [PATCH] Adds fragment for drafts and entry in menu --- .../mastodon/drawers/DraftsListAdapter.java | 44 ++++++++- .../fragments/DisplayDraftsFragment.java | 87 ++++++++++++++++++ .../main/res/drawable-hdpi/ic_mode_edit.png | Bin 0 -> 185 bytes .../main/res/drawable-ldpi/ic_mode_edit.png | Bin 0 -> 208 bytes .../main/res/drawable-mdpi/ic_mode_edit.png | Bin 0 -> 151 bytes .../main/res/drawable-xhdpi/ic_mode_edit.png | Bin 0 -> 213 bytes .../main/res/drawable-xxhdpi/ic_mode_edit.png | Bin 0 -> 260 bytes .../res/drawable-xxxhdpi/ic_mode_edit.png | Bin 0 -> 288 bytes app/src/main/res/layout/drawer_draft.xml | 3 +- app/src/main/res/layout/fragment_drafts.xml | 66 +++++++++++++ .../main/res/menu/activity_main_drawer.xml | 4 + app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 14 files changed, 202 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java create mode 100644 app/src/main/res/drawable-hdpi/ic_mode_edit.png create mode 100644 app/src/main/res/drawable-ldpi/ic_mode_edit.png create mode 100644 app/src/main/res/drawable-mdpi/ic_mode_edit.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_mode_edit.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_mode_edit.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_mode_edit.png create mode 100644 app/src/main/res/layout/fragment_drafts.xml diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java index bdd6d9b74..509e7b430 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/DraftsListAdapter.java @@ -15,6 +15,9 @@ package fr.gouv.etalab.mastodon.drawers; * see . */ +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 storedStatuses){ this.storedStatuses = storedStatuses; this.context = context; layoutInflater = LayoutInflater.from(context); draftsListAdapter = this; + this.clickable = false; + } + + public DraftsListAdapter(Context context, List 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; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java new file mode 100644 index 000000000..0289721b6 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayDraftsFragment.java @@ -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 . */ + +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 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; + } + + +} diff --git a/app/src/main/res/drawable-hdpi/ic_mode_edit.png b/app/src/main/res/drawable-hdpi/ic_mode_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..6b6432cdc554373964c3932c313770972861ef11 GIT binary patch literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^(jd&i0wmS%+S~(D4W2HJAr-goUa%H&a1da*;8$RD zUEqO0(9B0dLN~7^S^9NG7mjac4*1sb{I9ajETCH$JYD@<);T3K0RT?dN~Zt- literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-ldpi/ic_mode_edit.png b/app/src/main/res/drawable-ldpi/ic_mode_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..1b03caa0c9503925e45c2e7415fed07f8596fc10 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp@Ak4uAB#T}@sR2^cJzX3_DsCkwDDW8=P2gy0yus6P zwBsUA&;kA)emA> zi%s@bFna!A{HVO*Slx}HoL#y-iZQFH$JBE6~ofno)R+$UeY*?FG5%&dj;fi^LCy85}Sb4q9e014MO AhyVZp literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_mode_edit.png b/app/src/main/res/drawable-xhdpi/ic_mode_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..233bd313fceb6bb41ebfec6cb141c85a1ffe778c GIT binary patch literal 213 zcmV;`04o29P)9k429tzH`+I|_5F11Rwxv_AmW47h1BYlqC;Iwa?s73>;m}+A@KLi6iC6II~y-n zaHV_I)ZSxb*GrRrQW9LiIDPx+NCk)exx0#YNSrgQ<-jpI@*{( zl|z3;ZD#^iS>7*ZOw=^Lyw= literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_mode_edit.png b/app/src/main/res/drawable-xxhdpi/ic_mode_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..3f0af2e5b47b000653f319e9d983327d32280559 GIT binary patch literal 260 zcmeAS@N?(olHy`uVBq!ia0vp^W+2SL0wmRZ7KH(+)1EGlAr-gYUb5yo-H5<=|aIj?H43UzOyy^Etm= zy}F2h`(X=_P^%q_TyqZx)ygzh6$ZYpxmh6T#&hbZs?Dp}%#*p!eGUF9ve3dl)PK=p uqjymfsZ#>oBvYrDE3&Gh!_>(CZ#j$lr@g2@BBcTJ7K5j&pUXO@geCx}6=4Jb literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_mode_edit.png b/app/src/main/res/drawable-xxxhdpi/ic_mode_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..bbe6222bee65038620e617602cf1cc3053dc7fe9 GIT binary patch literal 288 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY0wn)GsXhawo_o4DhE&{odt;+ulY>C(!*rz^ z9c|klM|8VNSg>7d?7Eh+pmEtL9=9TP@dNLQEB>2(VBIY)vtUY4a%K>(uO(l_!%kZx zwsSn;d-ey1St#)_zMTHphpSM=)38rEQ}*eOiDt4(dV05PzBSiX>1E>9Q|3C8J<4~V z_EOH(<=;CyBq8hfyDgKu7Ut`G;W_51H^<^+udo{Lxs%ZrzL!qTzO1sdn8$PFoLMI6 zj|A3ivUv1|_qmdv|D44Zk2)rw&^-FGvslPoCXDZfMZ)8TUS=~tsTVmvmwF##lxEM7 j*-&@@!dN;*s#4z0?Cg56UL9eeml-@={an^LB{Ts5l@@f< literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/drawer_draft.xml b/app/src/main/res/layout/drawer_draft.xml index 3932994f3..c00591a46 100644 --- a/app/src/main/res/layout/drawer_draft.xml +++ b/app/src/main/res/layout/drawer_draft.xml @@ -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"> + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index c5d8508ea..70a6f6ba7 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -31,6 +31,10 @@ android:id="@+id/nav_scheduled" android:icon="@drawable/ic_schedule_black" android:title="@string/scheduled_toots" /> + Geteilt von Mastalab Antworten Benutzername - + Entwürfe Neue Beiträge sind verfügbar! Anzeigen? Home diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 623f060e0..c71843bf8 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -58,7 +58,7 @@ Partagé via Mastalab Réponses Nom d\'utilisateur - + Brouillons De nouvelles données sont disponibles ! Souhaitez-vous les afficher ? Accueil diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index edd3dc058..f9e324227 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -58,7 +58,7 @@ Shared via Mastalab Replies User name - + Drafts New data are available! Do you want to display them? Home