diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceFederatedActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceFederatedActivity.java index 721eafadd..d358fc64e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceFederatedActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/InstanceFederatedActivity.java @@ -42,6 +42,7 @@ import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; +import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; @@ -73,17 +74,13 @@ import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK; public class InstanceFederatedActivity extends BaseActivity { - private FloatingActionButton add_new; public static String currentLocale; private TabLayout tabLayout; private ViewPager viewPager; - private String userIdService; - private AppBarLayout appBar; - private String userId; - private String instance; private PagerAdapter adapter; boolean isLoadingInstance = false; private AutoCompleteTextView instance_list; + private CheckBox peertube_instance; private String oldSearch; private RelativeLayout no_action; @@ -130,6 +127,7 @@ public class InstanceFederatedActivity extends BaseActivity { dialogBuilder.setView(dialogView); instance_list = dialogView.findViewById(R.id.search_instance); + peertube_instance = dialogView.findViewById(R.id.peertube_instance); instance_list.setFilters(new InputFilter[]{new InputFilter.LengthFilter(60)}); dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() { @Override @@ -140,13 +138,18 @@ public class InstanceFederatedActivity extends BaseActivity { @Override public void run() { try { - String response = new HttpsConnection(InstanceFederatedActivity.this).get("https://" + instanceName + "/api/v1/timelines/public?local=true", 10, null, null); + if( !peertube_instance.isChecked()) + new HttpsConnection(InstanceFederatedActivity.this).get("https://" + instanceName + "/api/v1/timelines/public?local=true", 10, null, null); + else + new HttpsConnection(InstanceFederatedActivity.this).get("https://" + instanceName + "/api/v1/videos/", 10, null, null); runOnUiThread(new Runnable() { public void run() { JSONObject resobj; dialog.dismiss(); - new InstancesDAO(InstanceFederatedActivity.this, db).insertInstance(instanceName); - + if( peertube_instance.isChecked()) + new InstancesDAO(InstanceFederatedActivity.this, db).insertInstance(instanceName, "PEERTUBE"); + else + new InstancesDAO(InstanceFederatedActivity.this, db).insertInstance(instanceName, "MASTODON"); Helper.addTab(tabLayout, adapter, instanceName); adapter = new InstanceFederatedActivity.PagerAdapter (getSupportFragmentManager(), tabLayout.getTabCount()); @@ -300,7 +303,6 @@ public class InstanceFederatedActivity extends BaseActivity { Helper.canPin = false; Helper.fillMapEmoji(getApplicationContext()); //Here, the user is authenticated - appBar = findViewById(R.id.appBar); Toolbar toolbar = findViewById(R.id.toolbar); if( theme == THEME_BLACK) toolbar.setBackgroundColor(ContextCompat.getColor(InstanceFederatedActivity.this, R.color.black)); @@ -356,11 +358,11 @@ public class InstanceFederatedActivity extends BaseActivity { currentLocale = Helper.currentLocale(getApplicationContext()); - add_new = findViewById(R.id.add_new); + FloatingActionButton add_new = findViewById(R.id.add_new); - userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); - instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext())); + String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null); + Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId); if( account == null){ diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index e450e19ee..b0216fd61 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -559,7 +559,7 @@ public class API { List howToVideos = new ArrayList<>(); try { HttpsConnection httpsConnection = new HttpsConnection(context); - String response = httpsConnection.get("https://peertube.fr/api/v1/video-channels/bb32394a-a6d2-4f41-9b8e-ad9514a66009/videos", 60, null, null); + String response = httpsConnection.get("https://peertube.social/api/v1/video-channels/bb32394a-a6d2-4f41-9b8e-ad9514a66009/videos", 60, null, null); JSONArray jsonArray = new JSONObject(response).getJSONArray("data"); howToVideos = parseHowTos(jsonArray); } catch (HttpsConnection.HttpsConnectionException e) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/RemoteInstance.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/RemoteInstance.java new file mode 100644 index 000000000..7024ecd03 --- /dev/null +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/RemoteInstance.java @@ -0,0 +1,46 @@ +/* Copyright 2018 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 . */ +package fr.gouv.etalab.mastodon.client.Entities; + + +/** + * Created by Thomas on 05/10/2018. + * Manages following instances + */ + +public class RemoteInstance { + + private String host; + private String type; + + public RemoteInstance(){} + + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/HowToVideosAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/HowToVideosAdapter.java index e5ce1df64..7d7f80f51 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/HowToVideosAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/HowToVideosAdapter.java @@ -118,14 +118,14 @@ public class HowToVideosAdapter extends BaseAdapter implements OnListActionInter next.setBounds(0,0,(int) (30 * scale + 0.5f),(int) (30 * scale + 0.5f)); holder.how_to_description.setCompoundDrawables(null, null, next, null); Glide.with(holder.how_to_image.getContext()) - .load("https://peertube.fr" + howToVideo.getThumbnailPath()) + .load("https://peertube.social" + howToVideo.getThumbnailPath()) .into(holder.how_to_image); holder.how_to_container.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(context, WebviewActivity.class); Bundle b = new Bundle(); - String finalUrl = "https://peertube.fr" + howToVideo.getEmbedPath(); + String finalUrl = "https://peertube.social" + howToVideo.getEmbedPath(); b.putString("url", finalUrl); b.putBoolean("peertubeLink", true); Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$"); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/InstancesDAO.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/InstancesDAO.java index 6538185d5..0e4c9e81c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/InstancesDAO.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/InstancesDAO.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance; import fr.gouv.etalab.mastodon.helper.Helper; @@ -53,10 +54,11 @@ public class InstancesDAO { * Insert an instance name in database * @param instanceName String */ - public void insertInstance(String instanceName) { + public void insertInstance(String instanceName, String type) { ContentValues values = new ContentValues(); values.put(Sqlite.COL_INSTANCE, instanceName.trim()); values.put(Sqlite.COL_USER_ID, userId); + values.put(Sqlite.COL_INSTANCE_TYPE, type); values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(new Date())); //Inserts search try{ @@ -92,9 +94,9 @@ public class InstancesDAO { /** * Returns all instances in db for a user - * @return instances List + * @return instances List */ - public List getAllInstances(){ + public List getAllInstances(){ try { Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null); return cursorToListSearch(c); @@ -107,9 +109,9 @@ public class InstancesDAO { /** * Returns instance by its nale in db - * @return instance List + * @return instance List */ - public List getInstanceByName(String keyword){ + public List getInstanceByName(String keyword){ try { Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_INSTANCE + " = \"" + keyword + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null, null, null, null, null); return cursorToListSearch(c); @@ -122,19 +124,20 @@ public class InstancesDAO { /*** * Method to hydrate stored instances from database * @param c Cursor - * @return List + * @return List */ - private List cursorToListSearch(Cursor c){ + private List cursorToListSearch(Cursor c){ //No element found if (c.getCount() == 0) return null; - List instances = new ArrayList<>(); + List remoteInstances = new ArrayList<>(); while (c.moveToNext() ) { - instances.add(c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE))); + RemoteInstance remoteInstance = new RemoteInstance(); + remoteInstance.setHost(c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE))); + remoteInstance.setType(c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE)) == null?"MASTODON":c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE))); } //Close the cursor c.close(); - //Search list is returned - return instances; + return remoteInstances; } } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java index 5c8252361..970c4c32f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/sqlite/Sqlite.java @@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper; public class Sqlite extends SQLiteOpenHelper { - public static final int DB_VERSION = 13; + public static final int DB_VERSION = 14; public static final String DB_NAME = "mastodon_etalab_db"; public static SQLiteDatabase db; private static Sqlite sInstance; @@ -160,10 +160,10 @@ public class Sqlite extends SQLiteOpenHelper { private final String CREATE_UNIQUE_CACHE_INDEX = "CREATE UNIQUE INDEX instance_statusid on " + TABLE_STATUSES_CACHE + "(" + COL_INSTANCE +"," + COL_STATUS_ID + ")"; - + static final String COL_INSTANCE_TYPE = "INSTANCE_TYPE"; private final String CREATE_TABLE_INSTANCES = "CREATE TABLE " + TABLE_INSTANCES + " (" + COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " - + COL_INSTANCE + " TEXT NOT NULL, " + COL_USER_ID + " TEXT NOT NULL, " + COL_DATE_CREATION + " TEXT NOT NULL)"; + + COL_INSTANCE + " TEXT NOT NULL, " + COL_USER_ID + " TEXT NOT NULL, " + COL_INSTANCE_TYPE + " TEXT, " + COL_DATE_CREATION + " TEXT NOT NULL)"; public Sqlite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { @@ -226,6 +226,8 @@ public class Sqlite extends SQLiteOpenHelper { db.execSQL(CREATE_TABLE_INSTANCES); case 12: db.execSQL("ALTER TABLE " + TABLE_USER_ACCOUNT + " ADD COLUMN "+ COL_EMOJIS + " TEXT"); + case 13: + db.execSQL("ALTER TABLE " + TABLE_INSTANCES + " ADD COLUMN "+ COL_INSTANCE_TYPE + " TEXT"); default: break; } diff --git a/app/src/main/res/layout/search_instance.xml b/app/src/main/res/layout/search_instance.xml index c6412a2e7..c090e5567 100644 --- a/app/src/main/res/layout/search_instance.xml +++ b/app/src/main/res/layout/search_instance.xml @@ -10,4 +10,9 @@ android:hint="@string/instance" android:maxLines="1" /> + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 25f1650dc..e06e907d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -633,6 +633,7 @@ The domain is no longer blocked! Fetching remote status Comment + Peertube instance Never