fix some issues

This commit is contained in:
Thomas 2020-07-27 19:08:16 +02:00
parent 42b17d8d71
commit bd5ec0ad0f
7 changed files with 35 additions and 13 deletions

View File

@ -94,6 +94,7 @@ import java.util.regex.Matcher;
import app.fedilab.android.BuildConfig;
import app.fedilab.android.R;
import app.fedilab.android.asynctasks.DownloadTrackingDomainsAsyncTask;
import app.fedilab.android.asynctasks.ManageFiltersAsyncTask;
import app.fedilab.android.asynctasks.RetrieveAccountsAsyncTask;
import app.fedilab.android.asynctasks.RetrieveFeedsAsyncTask;
@ -106,7 +107,6 @@ import app.fedilab.android.asynctasks.RetrieveStoriesAsyncTask;
import app.fedilab.android.asynctasks.SyncTimelinesAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoAsyncTask;
import app.fedilab.android.asynctasks.UpdateAccountInfoByIDAsyncTask;
import app.fedilab.android.client.API;
import app.fedilab.android.client.APIResponse;
import app.fedilab.android.client.Entities.Account;
import app.fedilab.android.client.Entities.Announcement;
@ -1340,6 +1340,15 @@ public abstract class BaseMainActivity extends BaseActivity
mutedAccount = new TempMuteDAO(BaseMainActivity.this, db).getAllTimeMuted(account);
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA) {
new RetrieveFeedsAsyncTask(BaseMainActivity.this, RetrieveFeedsAsyncTask.Type.ANNOUNCEMENTS, null, BaseMainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (BuildConfig.lite) {
String datesupdate = sharedpreferences.getString(Helper.TRACKING_LAST_UPDATE, null);
Date dateLastUpdate = Helper.stringToDate(BaseMainActivity.this, datesupdate);
Date dateUpdate = new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(10));
//Refresh tracking db if needed
if (datesupdate == null || dateUpdate.after(dateLastUpdate)) {
new DownloadTrackingDomainsAsyncTask(BaseMainActivity.this).execute();
}
}
}
}

View File

@ -586,8 +586,7 @@ public class LoginActivity extends BaseActivity {
}
runOnUiThread(() -> {
JSONObject resobj;
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU && socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA)
{
if (socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.GNU && socialNetwork != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {
try {
resobj = new JSONObject(response);
String token = resobj.getString("access_token");
@ -608,8 +607,7 @@ public class LoginActivity extends BaseActivity {
} catch (JSONException e) {
e.printStackTrace();
}
} else
{
} else {
try {
resobj = new JSONObject(response);
Account account = GNUAPI.parseAccountResponse(resobj);
@ -628,7 +626,7 @@ public class LoginActivity extends BaseActivity {
if (userExists) {
new AccountDAO(LoginActivity.this, db).updateAccount(account);
}else {
} else {
if (account.getUsername() != null && account.getCreated_at() != null)
new AccountDAO(LoginActivity.this, db).insertAccount(account);
}

View File

@ -16,6 +16,7 @@ package app.fedilab.android.asynctasks;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Handler;
@ -28,15 +29,19 @@ import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.net.ssl.HttpsURLConnection;
import app.fedilab.android.R;
import app.fedilab.android.helper.Helper;
import app.fedilab.android.sqlite.DomainBlockDAO;
import app.fedilab.android.sqlite.Sqlite;
import es.dmoral.toasty.Toasty;
import static android.content.Context.MODE_PRIVATE;
/**
* Created by NickFreeman on 11/05/2019.
* Download the list of blocked tracking domains for build-in browser
@ -52,6 +57,10 @@ public class DownloadTrackingDomainsAsyncTask extends AsyncTask<Void, Void, Bool
this.update_tracking_domains = new WeakReference<>(update_tracking_domains);
}
public DownloadTrackingDomainsAsyncTask(Context context) {
this.context = new WeakReference<>(context);
}
@Override
protected Boolean doInBackground(Void... params) {
try {
@ -71,6 +80,10 @@ public class DownloadTrackingDomainsAsyncTask extends AsyncTask<Void, Void, Bool
SQLiteDatabase db = Sqlite.getInstance(context.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
new DomainBlockDAO(context.get(), db).set(domains);
SharedPreferences sharedpreferences = context.get().getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(Helper.TRACKING_LAST_UPDATE, Helper.dateToString(new Date()));
editor.apply();
return true;
} catch (IOException e) {
e.printStackTrace();
@ -80,7 +93,9 @@ public class DownloadTrackingDomainsAsyncTask extends AsyncTask<Void, Void, Bool
@Override
protected void onPreExecute() {
update_tracking_domains.get().setEnabled(false);
if (update_tracking_domains != null) {
update_tracking_domains.get().setEnabled(false);
}
}
@Override

View File

@ -59,10 +59,10 @@ public class UpdateAccountInfoByIDAsyncTask extends AsyncTask<Void, Void, Void>
Account account = null;
if (social == UpdateAccountInfoAsyncTask.SOCIAL.MASTODON || social == UpdateAccountInfoAsyncTask.SOCIAL.PLEROMA || social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
account = new API(this.contextReference.get()).verifyCredentials();
if( social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED){
if (social == UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
account.setSocial("PIXELFED");
}
}else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
} else if (social == UpdateAccountInfoAsyncTask.SOCIAL.PEERTUBE) {
account = new PeertubeAPI(this.contextReference.get()).verifyCredentials();
account.setSocial("PEERTUBE");
} else if (social == UpdateAccountInfoAsyncTask.SOCIAL.GNU || social == UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA) {

View File

@ -2574,7 +2574,7 @@ public class API {
}
account.setRefresh_token(newRefreshToken);
account.setToken(newToken);
if( account.getHeader() == null){
if (account.getHeader() == null) {
account.setHeader("");
account.setHeader_static("");
}

View File

@ -476,7 +476,7 @@ public class BaseHelper {
//End points
public static final String EP_AUTHORIZE = "/oauth/authorize";
public static final String TRACKING_LAST_UPDATE = "tracking_last_update";
//Proxy
public static final String SET_PROXY_ENABLED = "set_proxy_enabled";
public static final String SET_PROXY_TYPE = "set_proxy_type";

View File

@ -123,7 +123,7 @@ public class AccountDAO {
values.put(Sqlite.COL_HEADER_STATIC, account.getHeader_static());
values.put(Sqlite.COL_CREATED_AT, Helper.dateToString(account.getCreated_at()));
values.put(Sqlite.COL_EMOJIS, Helper.emojisToStringStorage(account.getEmojis()));
if( account.getSocial() != null) {
if (account.getSocial() != null) {
values.put(Sqlite.COL_SOCIAL, account.getSocial());
}
if (account.getClient_id() != null && account.getClient_secret() != null) {
@ -141,7 +141,7 @@ public class AccountDAO {
return db.update(Sqlite.TABLE_USER_ACCOUNT,
values, Sqlite.COL_USER_ID + " = ? AND " + Sqlite.COL_INSTANCE + " =?",
new String[]{account.getId(), account.getInstance()});
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
return -1;
}