Fix profile issue for remote instances

This commit is contained in:
stom79 2018-08-22 09:04:43 +02:00
parent b3d235d64b
commit e40f807aa0
3 changed files with 98 additions and 25 deletions

View File

@ -7,8 +7,8 @@ android {
applicationId "fr.gouv.etalab.mastodon"
minSdkVersion 15
targetSdkVersion 27
versionCode 127
versionName "1.10.3"
versionCode 128
versionName "1.10.4-beta-1"
}
flavorDimensions "default"
buildTypes {
@ -24,7 +24,10 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
productFlavors {
fdroid {
}

View File

@ -1583,32 +1583,68 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
});
holder.status_account_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) {
holder.status_account_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( targetedId == null || !targetedId.equals(status.getAccount().getId())){
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", status.getAccount().getId());
intent.putExtras(b);
context.startActivity(intent);
if (targetedId == null || !targetedId.equals(status.getAccount().getId())) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", status.getAccount().getId());
intent.putExtras(b);
context.startActivity(intent);
}
}
}
});
});
holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())){
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", status.getReblog().getAccount().getId());
intent.putExtras(b);
context.startActivity(intent);
holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", status.getReblog().getAccount().getId());
intent.putExtras(b);
context.startActivity(intent);
}
}
}
});
});
}else{
holder.status_account_profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (targetedId == null || !targetedId.equals(status.getAccount().getId())) {
Account account = status.getAccount();
Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})");
Matcher matcher = instanceHost.matcher(status.getUrl());
String instance = null;
while (matcher.find()){
instance = matcher.group(1);
}
account.setInstance(instance);
CrossActions.doCrossProfile(context, account);
}
}
});
holder.status_account_profile_boost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (targetedId == null || !targetedId.equals(status.getReblog().getAccount().getId())) {
Account account = status.getReblog().getAccount();
Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})");
Matcher matcher = instanceHost.matcher(status.getUrl());
String instance = null;
while (matcher.find()){
instance = matcher.group(1);
}
account.setInstance(instance);
CrossActions.doCrossProfile(context, account);
}
}
});
}
if( status.getApplication() != null && getItemViewType(position) == FOCUSED_STATUS){
Application application = status.getApplication();

View File

@ -33,10 +33,12 @@ import java.util.List;
import fr.gouv.etalab.mastodon.activities.BaseActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.ShowConversationActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveRemoteDataAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
@ -196,6 +198,38 @@ public class CrossActions {
}
public static void doCrossProfile(final Context context, Account remoteAccount){
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
SQLiteDatabase db = Sqlite.getInstance(context, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(context, db).getAccountByID(userId);
new AsyncTask<Void, Void, Void>() {
private WeakReference<Context> contextReference = new WeakReference<>(context);
Results response;
@Override
protected Void doInBackground(Void... voids) {
API api = new API(contextReference.get(), account.getInstance(), account.getToken());
String url = "@" + remoteAccount.getAcct() + "@" + remoteAccount.getInstance();
response = api.search(url);
return null;
}
@Override
protected void onPostExecute(Void result) {
List<Account> remoteAccounts = response.getAccounts();
if( remoteAccounts != null && remoteAccounts.size() > 0) {
Intent intent = new Intent(context, ShowAccountActivity.class);
Bundle b = new Bundle();
b.putString("accountId", remoteAccounts.get(0).getId());
intent.putExtras(b);
context.startActivity(intent);
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR );
}
public static void doCrossReply(final Context context, final Status status, final RetrieveFeedsAsyncTask.Type type, boolean limitedToOwner){
List<Account> accounts = connectedAccounts(context, status, limitedToOwner);