Fix an issue with profile name not displayed
This commit is contained in:
parent
ad950dfe5f
commit
3b6c5d3296
|
@ -42,6 +42,7 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.AutoCompleteTextView;
|
import android.widget.AutoCompleteTextView;
|
||||||
|
import android.widget.CheckBox;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
import android.widget.RelativeLayout;
|
||||||
|
@ -73,17 +74,13 @@ import static fr.gouv.etalab.mastodon.helper.Helper.THEME_BLACK;
|
||||||
|
|
||||||
public class InstanceFederatedActivity extends BaseActivity {
|
public class InstanceFederatedActivity extends BaseActivity {
|
||||||
|
|
||||||
private FloatingActionButton add_new;
|
|
||||||
public static String currentLocale;
|
public static String currentLocale;
|
||||||
private TabLayout tabLayout;
|
private TabLayout tabLayout;
|
||||||
private ViewPager viewPager;
|
private ViewPager viewPager;
|
||||||
private String userIdService;
|
|
||||||
private AppBarLayout appBar;
|
|
||||||
private String userId;
|
|
||||||
private String instance;
|
|
||||||
private PagerAdapter adapter;
|
private PagerAdapter adapter;
|
||||||
boolean isLoadingInstance = false;
|
boolean isLoadingInstance = false;
|
||||||
private AutoCompleteTextView instance_list;
|
private AutoCompleteTextView instance_list;
|
||||||
|
private CheckBox peertube_instance;
|
||||||
private String oldSearch;
|
private String oldSearch;
|
||||||
private RelativeLayout no_action;
|
private RelativeLayout no_action;
|
||||||
|
|
||||||
|
@ -130,6 +127,7 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
dialogBuilder.setView(dialogView);
|
dialogBuilder.setView(dialogView);
|
||||||
|
|
||||||
instance_list = dialogView.findViewById(R.id.search_instance);
|
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)});
|
instance_list.setFilters(new InputFilter[]{new InputFilter.LengthFilter(60)});
|
||||||
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,13 +138,18 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
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() {
|
runOnUiThread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
JSONObject resobj;
|
JSONObject resobj;
|
||||||
dialog.dismiss();
|
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);
|
Helper.addTab(tabLayout, adapter, instanceName);
|
||||||
adapter = new InstanceFederatedActivity.PagerAdapter
|
adapter = new InstanceFederatedActivity.PagerAdapter
|
||||||
(getSupportFragmentManager(), tabLayout.getTabCount());
|
(getSupportFragmentManager(), tabLayout.getTabCount());
|
||||||
|
@ -300,7 +303,6 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
Helper.canPin = false;
|
Helper.canPin = false;
|
||||||
Helper.fillMapEmoji(getApplicationContext());
|
Helper.fillMapEmoji(getApplicationContext());
|
||||||
//Here, the user is authenticated
|
//Here, the user is authenticated
|
||||||
appBar = findViewById(R.id.appBar);
|
|
||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
if( theme == THEME_BLACK)
|
if( theme == THEME_BLACK)
|
||||||
toolbar.setBackgroundColor(ContextCompat.getColor(InstanceFederatedActivity.this, R.color.black));
|
toolbar.setBackgroundColor(ContextCompat.getColor(InstanceFederatedActivity.this, R.color.black));
|
||||||
|
@ -356,11 +358,11 @@ public class InstanceFederatedActivity extends BaseActivity {
|
||||||
currentLocale = Helper.currentLocale(getApplicationContext());
|
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);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
|
||||||
|
|
||||||
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
Account account = new AccountDAO(getApplicationContext(), db).getAccountByID(userId);
|
||||||
if( account == null){
|
if( account == null){
|
||||||
|
|
|
@ -559,7 +559,7 @@ public class API {
|
||||||
List<HowToVideo> howToVideos = new ArrayList<>();
|
List<HowToVideo> howToVideos = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
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");
|
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||||
howToVideos = parseHowTos(jsonArray);
|
howToVideos = parseHowTos(jsonArray);
|
||||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses>. */
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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));
|
next.setBounds(0,0,(int) (30 * scale + 0.5f),(int) (30 * scale + 0.5f));
|
||||||
holder.how_to_description.setCompoundDrawables(null, null, next, null);
|
holder.how_to_description.setCompoundDrawables(null, null, next, null);
|
||||||
Glide.with(holder.how_to_image.getContext())
|
Glide.with(holder.how_to_image.getContext())
|
||||||
.load("https://peertube.fr" + howToVideo.getThumbnailPath())
|
.load("https://peertube.social" + howToVideo.getThumbnailPath())
|
||||||
.into(holder.how_to_image);
|
.into(holder.how_to_image);
|
||||||
holder.how_to_container.setOnClickListener(new View.OnClickListener() {
|
holder.how_to_container.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent intent = new Intent(context, WebviewActivity.class);
|
Intent intent = new Intent(context, WebviewActivity.class);
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
String finalUrl = "https://peertube.fr" + howToVideo.getEmbedPath();
|
String finalUrl = "https://peertube.social" + howToVideo.getEmbedPath();
|
||||||
b.putString("url", finalUrl);
|
b.putString("url", finalUrl);
|
||||||
b.putBoolean("peertubeLink", true);
|
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})$");
|
Pattern link = Pattern.compile("(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,10})\\/videos\\/embed\\/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import fr.gouv.etalab.mastodon.client.Entities.RemoteInstance;
|
||||||
import fr.gouv.etalab.mastodon.helper.Helper;
|
import fr.gouv.etalab.mastodon.helper.Helper;
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,10 +54,11 @@ public class InstancesDAO {
|
||||||
* Insert an instance name in database
|
* Insert an instance name in database
|
||||||
* @param instanceName String
|
* @param instanceName String
|
||||||
*/
|
*/
|
||||||
public void insertInstance(String instanceName) {
|
public void insertInstance(String instanceName, String type) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Sqlite.COL_INSTANCE, instanceName.trim());
|
values.put(Sqlite.COL_INSTANCE, instanceName.trim());
|
||||||
values.put(Sqlite.COL_USER_ID, userId);
|
values.put(Sqlite.COL_USER_ID, userId);
|
||||||
|
values.put(Sqlite.COL_INSTANCE_TYPE, type);
|
||||||
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(new Date()));
|
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(new Date()));
|
||||||
//Inserts search
|
//Inserts search
|
||||||
try{
|
try{
|
||||||
|
@ -92,9 +94,9 @@ public class InstancesDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all instances in db for a user
|
* Returns all instances in db for a user
|
||||||
* @return instances List<String>
|
* @return instances List<RemoteInstance>
|
||||||
*/
|
*/
|
||||||
public List<String> getAllInstances(){
|
public List<RemoteInstance> getAllInstances(){
|
||||||
try {
|
try {
|
||||||
Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
||||||
return cursorToListSearch(c);
|
return cursorToListSearch(c);
|
||||||
|
@ -107,9 +109,9 @@ public class InstancesDAO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns instance by its nale in db
|
* Returns instance by its nale in db
|
||||||
* @return instance List<String>
|
* @return instance List<RemoteInstance>
|
||||||
*/
|
*/
|
||||||
public List<String> getInstanceByName(String keyword){
|
public List<RemoteInstance> getInstanceByName(String keyword){
|
||||||
try {
|
try {
|
||||||
Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_INSTANCE + " = \"" + keyword + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null, null, null, null, null);
|
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);
|
return cursorToListSearch(c);
|
||||||
|
@ -122,19 +124,20 @@ public class InstancesDAO {
|
||||||
/***
|
/***
|
||||||
* Method to hydrate stored instances from database
|
* Method to hydrate stored instances from database
|
||||||
* @param c Cursor
|
* @param c Cursor
|
||||||
* @return List<String>
|
* @return List<RemoteInstance>
|
||||||
*/
|
*/
|
||||||
private List<String> cursorToListSearch(Cursor c){
|
private List<RemoteInstance> cursorToListSearch(Cursor c){
|
||||||
//No element found
|
//No element found
|
||||||
if (c.getCount() == 0)
|
if (c.getCount() == 0)
|
||||||
return null;
|
return null;
|
||||||
List<String> instances = new ArrayList<>();
|
List<RemoteInstance> remoteInstances = new ArrayList<>();
|
||||||
while (c.moveToNext() ) {
|
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
|
//Close the cursor
|
||||||
c.close();
|
c.close();
|
||||||
//Search list is returned
|
return remoteInstances;
|
||||||
return instances;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||||
|
|
||||||
public class Sqlite extends 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 final String DB_NAME = "mastodon_etalab_db";
|
||||||
public static SQLiteDatabase db;
|
public static SQLiteDatabase db;
|
||||||
private static Sqlite sInstance;
|
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 "
|
private final String CREATE_UNIQUE_CACHE_INDEX = "CREATE UNIQUE INDEX instance_statusid on "
|
||||||
+ TABLE_STATUSES_CACHE + "(" + COL_INSTANCE +"," + COL_STATUS_ID + ")";
|
+ 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 + " ("
|
private final String CREATE_TABLE_INSTANCES = "CREATE TABLE " + TABLE_INSTANCES + " ("
|
||||||
+ COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
|
+ 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) {
|
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);
|
db.execSQL(CREATE_TABLE_INSTANCES);
|
||||||
case 12:
|
case 12:
|
||||||
db.execSQL("ALTER TABLE " + TABLE_USER_ACCOUNT + " ADD COLUMN "+ COL_EMOJIS + " TEXT");
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,4 +10,9 @@
|
||||||
android:hint="@string/instance"
|
android:hint="@string/instance"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
/>
|
/>
|
||||||
|
<CheckBox
|
||||||
|
android:text="@string/peertube_instance"
|
||||||
|
android:id="@+id/peertube_instance"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -633,6 +633,7 @@
|
||||||
<string name="toast_unblock_domain">The domain is no longer blocked!</string>
|
<string name="toast_unblock_domain">The domain is no longer blocked!</string>
|
||||||
<string name="retrieve_remote_status">Fetching remote status</string>
|
<string name="retrieve_remote_status">Fetching remote status</string>
|
||||||
<string name="comment">Comment</string>
|
<string name="comment">Comment</string>
|
||||||
|
<string name="peertube_instance">Peertube instance</string>
|
||||||
|
|
||||||
<string-array name="filter_expire">
|
<string-array name="filter_expire">
|
||||||
<item>Never</item>
|
<item>Never</item>
|
||||||
|
|
Loading…
Reference in New Issue