From daac10d40777562baeb0a69f9e9da4b33c2e6d18 Mon Sep 17 00:00:00 2001 From: tom79 Date: Sat, 2 Sep 2017 18:43:36 +0200 Subject: [PATCH 1/5] Prepares methods and values --- .../gouv/etalab/mastodon/helper/Helper.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java index c5ff7961c..ad3a4b7c4 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/Helper.java @@ -18,6 +18,7 @@ package fr.gouv.etalab.mastodon.helper; import android.app.Activity; +import android.preference.PreferenceManager; import android.support.annotation.RequiresApi; import android.support.v7.app.AlertDialog; import android.app.DownloadManager; @@ -81,6 +82,7 @@ import android.widget.TextView; import android.widget.Toast; import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import com.loopj.android.http.BuildConfig; import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; @@ -102,11 +104,13 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; +import java.lang.reflect.Type; import java.net.InetAddress; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -203,8 +207,10 @@ public class Helper { public static final String SET_PREVIEW_REPLIES_PP = "set_preview_replies_pp"; public static final String SET_TRANSLATOR = "set_translator"; public static final String SET_LED_COLOUR = "set_led_colour"; - public static final String SET_UNREAD_NOTIFICATIONS = "set_unread_notifications"; - public static final String SET_UNREAD_TOOTS = "set_unread_toots"; + private static final String SET_UNREAD_NOTIFICATIONS = "set_unread_notifications"; + private static final String SET_UNREAD_TOOTS = "set_unread_toots"; + private static final String SET_DEVELOPERS = "set_developers"; + private static final String SET_DEVELOPERS_CACHE_DATE = "set_developers_cache_date"; public static final int ATTACHMENT_ALWAYS = 1; public static final int ATTACHMENT_WIFI = 2; @@ -1672,4 +1678,31 @@ public class Helper { editor.apply(); } } + + + public static String[] developers = { + "https://mastodon.etalab.gouv.fr/@tschneider", + "https://mastodon.xyz/@PhotonQyv", + "https://social.tchncs.de/@angrytux" + }; + + public static void cacheDevelopers(Context context, ArrayList accounts){ + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + Gson gson = new Gson(); + String serializedAccounts = gson.toJson(accounts); + editor.putString(Helper.SET_DEVELOPERS, serializedAccounts); + editor.putString(Helper.SET_DEVELOPERS_CACHE_DATE, dateToString(context, new Date())); + editor.apply(); + } + + + public static ArrayList getDevelopers(Context context){ + SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + Gson gson = new Gson(); + String json = sharedpreferences.getString(Helper.SET_DEVELOPERS, null); + Type type = new TypeToken>() {}.getType(); + return gson.fromJson(json, type); + } + } From e1ce2153284085ee4f2e14a2749a89d3bd8b246e Mon Sep 17 00:00:00 2001 From: tom79 Date: Sat, 2 Sep 2017 19:15:29 +0200 Subject: [PATCH 2/5] prepares async --- .../mastodon/activities/AboutActivity.java | 95 +++++++++---------- .../activities/RemoteFollowActivity.java | 2 +- .../RetrieveRemoteAccountsAsyncTask.java | 5 +- .../OnRetrieveRemoteAccountInterface.java | 2 +- app/src/main/res/layout/activity_about.xml | 23 ++--- 5 files changed, 63 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java index 56802633c..af25ea2d1 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/AboutActivity.java @@ -31,14 +31,20 @@ import android.text.style.ClickableSpan; import android.view.MenuItem; import android.view.View; import android.widget.Button; +import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; +import java.util.ArrayList; import java.util.List; import fr.gouv.etalab.mastodon.asynctasks.RetrieveDeveloperAccountsAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteAccountsAsyncTask; import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; +import fr.gouv.etalab.mastodon.drawers.AccountSearchWebAdapter; import fr.gouv.etalab.mastodon.helper.Helper; +import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveSearcAccountshInterface; import mastodon.etalab.gouv.fr.mastodon.R; @@ -48,9 +54,12 @@ import mastodon.etalab.gouv.fr.mastodon.R; * About activity */ -public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcAccountshInterface { +public class AboutActivity extends AppCompatActivity implements OnRetrieveRemoteAccountInterface { - private Button about_developer; + private ListView lv_developers; + private ListView lv_contributors; + private List contributors = new ArrayList<>(); + private AccountSearchWebAdapter accountSearchWebAdapter; @SuppressWarnings("deprecation") @Override @@ -73,7 +82,8 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcA about_version.setText(getResources().getString(R.string.about_vesrion, version)); } catch (PackageManager.NameNotFoundException ignored) {} - about_developer = (Button) findViewById(R.id.about_developer); + lv_developers = (ListView) findViewById(R.id.lv_developers); + lv_contributors = (ListView) findViewById(R.id.lv_contributors); Button about_code = (Button) findViewById(R.id.about_code); Button about_license = (Button) findViewById(R.id.about_license); Button about_thekinrar = (Button) findViewById(R.id.about_thekinrar); @@ -93,17 +103,7 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcA startActivity(browserIntent); } }); - if(Helper.isLoggedIn(getApplicationContext())) { - about_developer.setEnabled(false); - new RetrieveDeveloperAccountsAsyncTask(getApplicationContext(),AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - about_developer.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://mastodon.etalab.gouv.fr/@tschneider")); - startActivity(browserIntent); - } - }); + about_license.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -120,32 +120,19 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcA } }); - TextView about_thanks = (TextView) findViewById(R.id.about_thanks_dev); - String currentText = about_thanks.getText().toString(); - SpannableString spanned_thanks = new SpannableString(currentText); - int startPosition = spanned_thanks.toString().indexOf("@PhotonQyv"); - int endPosition = startPosition + "@PhotonQyv".length(); - spanned_thanks.setSpan(new ClickableSpan() { - @Override - public void onClick(View textView) { - Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://mastodon.xyz/@PhotonQyv")); - startActivity(browserIntent); - } - @Override - public void updateDrawState(TextPaint ds) { - super.updateDrawState(ds); - } - }, startPosition, endPosition, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); - about_thanks.setText(spanned_thanks, TextView.BufferType.SPANNABLE); - about_thanks.setMovementMethod(LinkMovementMethod.getInstance()); if( theme == Helper.THEME_LIGHT) { - about_developer.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); about_code.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); about_thekinrar.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); about_translation.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); about_license.setTextColor(ContextCompat.getColor(getApplicationContext(), R.color.white)); } + + accountSearchWebAdapter = new AccountSearchWebAdapter(AboutActivity.this, contributors); + lv_contributors.setAdapter(accountSearchWebAdapter); + new RetrieveRemoteAccountsAsyncTask("tschneider", "mastodon.etalab.gouv.fr", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveRemoteAccountsAsyncTask("PhotonQyv", "mastodon.xyz", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + new RetrieveRemoteAccountsAsyncTask("angrytux", "social.tchncs.de", AboutActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -160,22 +147,34 @@ public class AboutActivity extends AppCompatActivity implements OnRetrieveSearcA } } + @Override - public void onRetrieveSearchAccounts(APIResponse apiResponse) { - about_developer.setEnabled(true); - final List accounts = apiResponse.getAccounts(); - if( accounts != null && accounts.size() > 0 && accounts.get(0) != null) { - about_developer.setOnClickListener(null); - about_developer.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(AboutActivity.this, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", accounts.get(0).getId()); - intent.putExtras(b); - startActivity(intent); - } - }); + public void onRetrieveRemoteAccount(boolean error, String name, String username, String instance_name, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount) { + if( error){ + return; } + Account account = new Account(); + account.setInstance(instance_name); + account.setAcct(username + "@" + instance_name); + account.setAvatar(avatar); + account.setDisplay_name(username); + account.setStatuses_count(statusCount); + account.setFollowers_count(followersCount); + account.setFollowing_count(followingCount); + account.setUsername(name); + account.setLocked(locked); + account.setNote(bio); + + + if( username.equals("tschneider")) { + List selectedAccount = new ArrayList<>(); + selectedAccount.add(account); + AccountSearchWebAdapter accountSearchWebAdapter = new AccountSearchWebAdapter(AboutActivity.this, selectedAccount); + lv_developers.setAdapter(accountSearchWebAdapter); + }else { + contributors.add(account); + accountSearchWebAdapter.notifyDataSetChanged(); + } + } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java index 55262e673..3047deb47 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/RemoteFollowActivity.java @@ -261,7 +261,7 @@ public class RemoteFollowActivity extends AppCompatActivity implements OnRetriev @Override - public void onRetrieveRemoteAccount(boolean error, String name, String username, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount) { + public void onRetrieveRemoteAccount(boolean error, String name, String username, String instance_name, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount) { loader.setVisibility(View.GONE); rf_search.setEnabled(true); if( error){ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteAccountsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteAccountsAsyncTask.java index 94141cbd1..80a44d182 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteAccountsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteAccountsAsyncTask.java @@ -15,6 +15,8 @@ package fr.gouv.etalab.mastodon.asynctasks; import android.os.AsyncTask; +import android.util.Log; + import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; @@ -66,13 +68,14 @@ public class RetrieveRemoteAccountsAsyncTask extends AsyncTask followersCount = Integer.parseInt(countElement.get(2).html()); } catch (IOException | IndexOutOfBoundsException e) { error = true; + e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { - listener.onRetrieveRemoteAccount(error, name, username, islocked, avatar, bio, statusCount, followingCount, followersCount); + listener.onRetrieveRemoteAccount(error, name, username, instance, islocked, avatar, bio, statusCount, followingCount, followersCount); } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRemoteAccountInterface.java b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRemoteAccountInterface.java index 4d984933e..4388e231d 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRemoteAccountInterface.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/interfaces/OnRetrieveRemoteAccountInterface.java @@ -20,5 +20,5 @@ package fr.gouv.etalab.mastodon.interfaces; * Interface for retrieving a remote account */ public interface OnRetrieveRemoteAccountInterface { - void onRetrieveRemoteAccount(boolean error, String name, String username, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount); + void onRetrieveRemoteAccount(boolean error, String name, String username, String instance, boolean locked, String avatar, String bio, int statusCount, int followingCount, int followersCount); } diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index eb2f23db9..69ac2d429 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -43,26 +43,20 @@ - - -