Add to menu
This commit is contained in:
parent
bfe66fd93c
commit
bafb6da9ea
|
@ -48,7 +48,6 @@ import android.support.v7.widget.SwitchCompat;
|
|||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -202,6 +201,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
private ImageView delete_instance;
|
||||
public static String displayPeertube = null;
|
||||
private PopupMenu popup;
|
||||
private String instance_id;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -310,7 +310,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
dialogBuilder.setPositiveButton(R.string.validate, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
new InstancesDAO(BaseMainActivity.this, db).remove(title);
|
||||
new InstancesDAO(BaseMainActivity.this, db).remove(instance_id);
|
||||
BaseMainActivity.this.onBackPressed();
|
||||
}
|
||||
});
|
||||
|
@ -355,7 +355,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
SubMenu submMastodon = popup.getMenu().findItem(R.id.action_show_mastodon).getSubMenu();
|
||||
SubMenu submPeertube = popup.getMenu().findItem(R.id.action_show_peertube).getSubMenu();
|
||||
SubMenu submChannel = popup.getMenu().findItem(R.id.action_show_channel).getSubMenu();
|
||||
int i = 0, j = 0 , k = 0, l = 0;
|
||||
int i = 0, j = 0 , k = 0;
|
||||
for (RemoteInstance remoteInstance : remoteInstances) {
|
||||
if (remoteInstance.getType() == null || remoteInstance.getType().equals("MASTODON")) {
|
||||
MenuItem itemPlaceHolder = submMastodon.findItem(R.id.mastodon_instances);
|
||||
|
@ -373,6 +373,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
bundle.putString("remote_instance", remoteInstance.getHost());
|
||||
statusFragment.setArguments(bundle);
|
||||
String fragmentTag = "REMOTE_INSTANCE";
|
||||
instance_id = remoteInstance.getDbID();
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
|
||||
|
@ -386,7 +387,40 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
}
|
||||
});
|
||||
i++;
|
||||
}if (remoteInstance.getType() == null || remoteInstance.getType().equals("PEERTUBE")) {
|
||||
}
|
||||
if (remoteInstance.getType() == null || remoteInstance.getType().equals("PEERTUBE_CHANNEL")) {
|
||||
MenuItem itemPlaceHolder = submChannel.findItem(R.id.channel_instances);
|
||||
if( itemPlaceHolder != null)
|
||||
itemPlaceHolder.setVisible(false);
|
||||
MenuItem item = submChannel.add(0, k, Menu.NONE, remoteInstance.getId() + " - " +remoteInstance.getHost());
|
||||
item.setIcon(R.drawable.ic_list_instance);
|
||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
DisplayStatusFragment statusFragment;
|
||||
Bundle bundle = new Bundle();
|
||||
statusFragment = new DisplayStatusFragment();
|
||||
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE);
|
||||
bundle.putString("remote_instance", remoteInstance.getHost());
|
||||
bundle.putString("remote_channel_name", remoteInstance.getId());
|
||||
statusFragment.setArguments(bundle);
|
||||
instance_id = remoteInstance.getDbID();
|
||||
String fragmentTag = "REMOTE_INSTANCE";
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
|
||||
main_app_container.setVisibility(View.VISIBLE);
|
||||
viewPager.setVisibility(View.GONE);
|
||||
tabLayout.setVisibility(View.GONE);
|
||||
toolbarTitle.setVisibility(View.VISIBLE);
|
||||
delete_instance.setVisibility(View.VISIBLE);
|
||||
toolbarTitle.setText(remoteInstance.getHost());
|
||||
return false;
|
||||
}
|
||||
});
|
||||
k++;
|
||||
}
|
||||
if (remoteInstance.getType() == null || remoteInstance.getType().equals("PEERTUBE")) {
|
||||
MenuItem itemPlaceHolder = submPeertube.findItem(R.id.peertube_instances);
|
||||
if( itemPlaceHolder != null)
|
||||
itemPlaceHolder.setVisible(false);
|
||||
|
@ -402,6 +436,7 @@ public abstract class BaseMainActivity extends BaseActivity
|
|||
bundle.putString("remote_instance", remoteInstance.getHost());
|
||||
statusFragment.setArguments(bundle);
|
||||
String fragmentTag = "REMOTE_INSTANCE";
|
||||
instance_id = remoteInstance.getDbID();
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction()
|
||||
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
|
||||
|
|
|
@ -54,7 +54,7 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
private boolean showReply = false;
|
||||
private WeakReference<Context> contextReference;
|
||||
private FilterToots filterToots;
|
||||
private String instanceName;
|
||||
private String instanceName,remoteInstance, name;
|
||||
|
||||
public enum Type{
|
||||
HOME,
|
||||
|
@ -126,10 +126,19 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
this.tag = tag;
|
||||
}
|
||||
|
||||
public RetrieveFeedsAsyncTask(Context context, String remoteInstance, String name, String max_id, OnRetrieveFeedsInterface onRetrieveFeedsInterface){
|
||||
this.contextReference = new WeakReference<>(context);
|
||||
this.remoteInstance = remoteInstance;
|
||||
this.max_id = max_id;
|
||||
this.listener = onRetrieveFeedsInterface;
|
||||
this.name = name;
|
||||
this.action = Type.REMOTE_INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
API api = new API(this.contextReference.get());
|
||||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
switch (action){
|
||||
case HOME:
|
||||
apiResponse = api.getHomeTimeline(max_id);
|
||||
|
@ -144,18 +153,21 @@ public class RetrieveFeedsAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||
apiResponse = api.getDirectTimeline(max_id);
|
||||
break;
|
||||
case REMOTE_INSTANCE:
|
||||
SQLiteDatabase db = Sqlite.getInstance(this.contextReference.get(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
List<RemoteInstance> remoteInstanceObj = new InstancesDAO(this.contextReference.get(), db).getInstanceByName(this.instanceName);
|
||||
if( remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("MASTODON")) {
|
||||
apiResponse = api.getPublicTimeline(this.instanceName, false, max_id);
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
|
||||
if( statusesTemp != null){
|
||||
for(fr.gouv.etalab.mastodon.client.Entities.Status status: statusesTemp){
|
||||
status.setType(action);
|
||||
if( this.name != null && this.remoteInstance != null){ //For Peertube channels
|
||||
apiResponse = api.getPeertubeChannelVideos(this.remoteInstance, this.name);
|
||||
}else{ //For other remote instance
|
||||
List<RemoteInstance> remoteInstanceObj = new InstancesDAO(this.contextReference.get(), db).getInstanceByName(this.instanceName);
|
||||
if( remoteInstanceObj != null && remoteInstanceObj.size() > 0 && remoteInstanceObj.get(0).getType().equals("MASTODON")) {
|
||||
apiResponse = api.getPublicTimeline(this.instanceName, false, max_id);
|
||||
List<fr.gouv.etalab.mastodon.client.Entities.Status> statusesTemp = apiResponse.getStatuses();
|
||||
if( statusesTemp != null){
|
||||
for(fr.gouv.etalab.mastodon.client.Entities.Status status: statusesTemp){
|
||||
status.setType(action);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
apiResponse = api.getPeertube(this.instanceName, max_id);
|
||||
}
|
||||
}else {
|
||||
apiResponse = api.getPeertube(this.instanceName, max_id);
|
||||
}
|
||||
break;
|
||||
case FAVOURITES:
|
||||
|
|
|
@ -16,7 +16,6 @@ package fr.gouv.etalab.mastodon.client;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -613,7 +612,6 @@ public class API {
|
|||
List<Account> accounts = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
Log.v(Helper.TAG,"url: " + String.format("https://"+instance+"/api/v1/accounts/%s/video-channels", name));
|
||||
String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/accounts/%s/video-channels", name), 60, null, null);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
accounts = parseAccountResponsePeertube(context, instance, jsonArray);
|
||||
|
@ -632,6 +630,34 @@ public class API {
|
|||
return apiResponse;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves Peertube videos from an instance *synchronously*
|
||||
* @return APIResponse
|
||||
*/
|
||||
public APIResponse getPeertubeChannelVideos(String instance, String name) {
|
||||
|
||||
List<Peertube> peertubes = new ArrayList<>();
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context);
|
||||
String response = httpsConnection.get(String.format("https://"+instance+"/api/v1/video-channels/%s/videos", name), 60, null, null);
|
||||
JSONArray jsonArray = new JSONObject(response).getJSONArray("data");
|
||||
peertubes = parsePeertube(instance, jsonArray);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
setError(e.getStatusCode(), e);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
apiResponse.setPeertubes(peertubes);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves Peertube videos from an instance *synchronously*
|
||||
* @return APIResponse
|
||||
|
@ -2887,7 +2913,6 @@ public class API {
|
|||
*/
|
||||
private static Account parseAccountResponsePeertube(Context context, String instance, JSONObject resobj){
|
||||
Account account = new Account();
|
||||
Log.v(Helper.TAG, String.valueOf(resobj));
|
||||
try {
|
||||
account.setId(resobj.get("id").toString());
|
||||
account.setUsername(resobj.get("name").toString());
|
||||
|
|
|
@ -24,6 +24,8 @@ public class RemoteInstance {
|
|||
|
||||
private String host;
|
||||
private String type;
|
||||
private String id;
|
||||
private String dbID;
|
||||
|
||||
public RemoteInstance(){}
|
||||
|
||||
|
@ -43,4 +45,20 @@ public class RemoteInstance {
|
|||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getDbID() {
|
||||
return dbID;
|
||||
}
|
||||
|
||||
public void setDbID(String dbID) {
|
||||
this.dbID = dbID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package fr.gouv.etalab.mastodon.drawers;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
@ -46,6 +47,8 @@ import fr.gouv.etalab.mastodon.helper.Helper;
|
|||
import fr.gouv.etalab.mastodon.interfaces.OnPostActionInterface;
|
||||
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
|
||||
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
|
||||
import fr.gouv.etalab.mastodon.sqlite.InstancesDAO;
|
||||
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
|
||||
|
||||
import static fr.gouv.etalab.mastodon.helper.Helper.withSuffix;
|
||||
|
||||
|
@ -142,16 +145,26 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
|||
});
|
||||
}
|
||||
|
||||
if( action != RetrieveAccountsAsyncTask.Type.CHANNELS){
|
||||
holder.account_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( holder.account_ds.getVisibility() == View.VISIBLE)
|
||||
holder.account_ds.setVisibility(View.GONE);
|
||||
else
|
||||
holder.account_ds.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}else{
|
||||
holder.account_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
holder.account_container.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if( holder.account_ds.getVisibility() == View.VISIBLE)
|
||||
holder.account_ds.setVisibility(View.GONE);
|
||||
else
|
||||
holder.account_ds.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
holder.account_dn.setText(Helper.shortnameToUnicode(account.getDisplay_name(), true));
|
||||
holder.account_un.setText(String.format("@%s",account.getUsername()));
|
||||
holder.account_ac.setText(account.getAcct());
|
||||
|
@ -239,11 +252,16 @@ public class AccountsListAdapter extends RecyclerView.Adapter implements OnPostA
|
|||
accountsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
if( statusAction == API.StatusAction.FOLLOW){
|
||||
for(Account account: accounts){
|
||||
if( account.getId().equals(targetedId))
|
||||
account.setFollowType(Account.followAction.FOLLOW);
|
||||
if( action == RetrieveAccountsAsyncTask.Type.CHANNELS){
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
new InstancesDAO(context, db).insertInstance(accounts.get(0).getAcct().split("@")[1], accounts.get(0).getAcct().split("@")[0], "PEERTUBE_CHANNEL");
|
||||
}else{
|
||||
for(Account account: accounts){
|
||||
if( account.getId().equals(targetedId))
|
||||
account.setFollowType(Account.followAction.FOLLOW);
|
||||
}
|
||||
accountsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
accountsListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
if( statusAction == API.StatusAction.UNFOLLOW){
|
||||
for(Account account: accounts){
|
||||
|
|
|
@ -34,7 +34,6 @@ import android.support.v7.widget.PopupMenu;
|
|||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
|
|
|
@ -24,7 +24,6 @@ import android.support.v4.widget.SwipeRefreshLayout;
|
|||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
|
@ -93,7 +93,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
private String remoteInstance;
|
||||
private List<String> mutedAccount;
|
||||
private String instanceType;
|
||||
private String search_peertube;
|
||||
private String search_peertube, remote_channel_name;
|
||||
|
||||
|
||||
public DisplayStatusFragment(){
|
||||
|
@ -121,6 +121,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
showReply = bundle.getBoolean("showReply",false);
|
||||
remoteInstance = bundle.getString("remote_instance", "");
|
||||
search_peertube = bundle.getString("search_peertube", null);
|
||||
remote_channel_name = bundle.getString("remote_channel_name", null);
|
||||
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
@ -167,7 +168,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && search_peertube != null)
|
||||
((Activity)context).setTitle(remoteInstance + " - " + search_peertube);
|
||||
|
||||
if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE && remote_channel_name != null)
|
||||
((Activity)context).setTitle(remote_channel_name + " - " + remoteInstance);
|
||||
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
|
||||
{
|
||||
|
@ -183,8 +185,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
else if( type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE ) {
|
||||
if( search_peertube == null)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( search_peertube == null) {
|
||||
if( remote_channel_name == null)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, remoteInstance, remote_channel_name, null,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
else
|
||||
asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else
|
||||
|
@ -262,8 +268,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE ) {
|
||||
if( search_peertube == null)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( search_peertube == null) {
|
||||
if( remote_channel_name == null)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, remoteInstance, remote_channel_name, null,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
else
|
||||
asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else {
|
||||
|
@ -289,8 +299,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
|
|||
else if (type == RetrieveFeedsAsyncTask.Type.TAG)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE ) {
|
||||
if( search_peertube == null)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
if( search_peertube == null) {
|
||||
if( remote_channel_name == null)
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, type, remoteInstance, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
else
|
||||
asyncTask = new RetrieveFeedsAsyncTask(context, remoteInstance, remote_channel_name, null,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
else
|
||||
asyncTask = new RetrievePeertubeSearchAsyncTask(context, remoteInstance, search_peertube, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}else {
|
||||
|
|
|
@ -34,7 +34,6 @@ import android.preference.PreferenceManager;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.load.DataSource;
|
||||
|
|
|
@ -36,14 +36,12 @@ public class InstancesDAO {
|
|||
|
||||
private SQLiteDatabase db;
|
||||
public Context context;
|
||||
private String userId;
|
||||
|
||||
public InstancesDAO(Context context, SQLiteDatabase db) {
|
||||
//Creation of the DB with tables
|
||||
this.context = context;
|
||||
this.db = db;
|
||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||
userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
|
||||
}
|
||||
|
||||
|
@ -54,10 +52,10 @@ public class InstancesDAO {
|
|||
* Insert an instance name in database
|
||||
* @param instanceName String
|
||||
*/
|
||||
public void insertInstance(String instanceName, String type) {
|
||||
public void insertInstance(String instanceName, String id, String type) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(Sqlite.COL_INSTANCE, instanceName.trim());
|
||||
values.put(Sqlite.COL_USER_ID, userId);
|
||||
values.put(Sqlite.COL_USER_ID, id);
|
||||
values.put(Sqlite.COL_INSTANCE_TYPE, type);
|
||||
values.put(Sqlite.COL_DATE_CREATION, Helper.dateToString(new Date()));
|
||||
//Inserts search
|
||||
|
@ -66,15 +64,8 @@ public class InstancesDAO {
|
|||
}catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
|
||||
//------- REMOVE -------
|
||||
|
||||
/***
|
||||
* Remove instance by its name
|
||||
* @return int
|
||||
*/
|
||||
public int remove(String instanceName){
|
||||
return db.delete(Sqlite.TABLE_INSTANCES, Sqlite.COL_INSTANCE + " = \"" + instanceName + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId+ "\"", null);
|
||||
public void insertInstance(String instanceName, String type) {
|
||||
insertInstance(instanceName, "null", type);
|
||||
}
|
||||
|
||||
//------- REMOVE -------
|
||||
|
@ -83,11 +74,21 @@ public class InstancesDAO {
|
|||
* Remove instance by its name
|
||||
* @return int
|
||||
*/
|
||||
public int cleanDoublon(){
|
||||
return db.delete(Sqlite.TABLE_INSTANCES, Sqlite.COL_ID + " NOT IN (" +
|
||||
" SELECT MIN("+Sqlite.COL_ID+")" +
|
||||
public int remove(String id){
|
||||
return db.delete(Sqlite.TABLE_INSTANCES, Sqlite.COL_ID + " = \"" + id + "\"", null);
|
||||
}
|
||||
|
||||
//------- REMOVE -------
|
||||
|
||||
/***
|
||||
* Remove instance by its name
|
||||
* @return int
|
||||
*/
|
||||
public void cleanDoublon(){
|
||||
db.delete(Sqlite.TABLE_INSTANCES, Sqlite.COL_ID + " NOT IN (" +
|
||||
" SELECT MIN(" + Sqlite.COL_ID + ")" +
|
||||
" FROM " + Sqlite.TABLE_INSTANCES +
|
||||
" GROUP BY "+ Sqlite.COL_INSTANCE + "," + Sqlite.COL_USER_ID +")", null);
|
||||
" GROUP BY " + Sqlite.COL_INSTANCE + "," + Sqlite.COL_USER_ID + ")", null);
|
||||
}
|
||||
|
||||
//------- GETTERS -------
|
||||
|
@ -98,7 +99,7 @@ public class InstancesDAO {
|
|||
*/
|
||||
public List<RemoteInstance> getAllInstances(){
|
||||
try {
|
||||
Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_USER_ID + " = '" + userId+ "'", null, null, null, Sqlite.COL_INSTANCE_TYPE + " ASC, "+Sqlite.COL_INSTANCE + " ASC", null);
|
||||
Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, null, null, null, null, Sqlite.COL_INSTANCE + " ASC", null);
|
||||
return cursorToListSearch(c);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
@ -113,7 +114,7 @@ public class InstancesDAO {
|
|||
*/
|
||||
public List<RemoteInstance> 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);
|
||||
Cursor c = db.query(Sqlite.TABLE_INSTANCES, null, Sqlite.COL_INSTANCE + " = \"" + keyword + "\"", null, null, null, null, null);
|
||||
return cursorToListSearch(c);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
@ -133,6 +134,8 @@ public class InstancesDAO {
|
|||
List<RemoteInstance> remoteInstances = new ArrayList<>();
|
||||
while (c.moveToNext() ) {
|
||||
RemoteInstance remoteInstance = new RemoteInstance();
|
||||
remoteInstance.setDbID(c.getString(c.getColumnIndex(Sqlite.COL_ID)));
|
||||
remoteInstance.setId(c.getString(c.getColumnIndex(Sqlite.COL_USER_ID)));
|
||||
remoteInstance.setHost(c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE)));
|
||||
remoteInstance.setType(c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE_TYPE)) == null?"MASTODON":c.getString(c.getColumnIndex(Sqlite.COL_INSTANCE_TYPE)));
|
||||
remoteInstances.add(remoteInstance);
|
||||
|
|
Loading…
Reference in New Issue