Fix search with PixelFed
This commit is contained in:
parent
cfd12ff64f
commit
a466487a49
|
@ -14,6 +14,8 @@
|
|||
* see <http://www.gnu.org/licenses>. */
|
||||
package app.fedilab.android.activities;
|
||||
|
||||
import static app.fedilab.android.jobs.BaseNotificationsSyncJob.NOTIFICATION_REFRESH;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
|
@ -45,7 +47,14 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.evernote.android.job.JobManager;
|
||||
import com.evernote.android.job.JobRequest;
|
||||
|
||||
import org.unifiedpush.android.connector.Registration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.client.Entities.Account;
|
||||
|
@ -348,26 +357,48 @@ public class SettingsActivity extends BaseActivity {
|
|||
editor.apply();
|
||||
});
|
||||
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_NOTIFY, true);
|
||||
LinearLayout notification_container = findViewById(R.id.notification_container);
|
||||
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_ALLOW_NOTIFICATION, true);
|
||||
final SwitchCompat switchCompatNotify = findViewById(R.id.set_notify);
|
||||
switchCompatNotify.setChecked(notify);
|
||||
|
||||
|
||||
if (notify) {
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
notification_container.setVisibility(View.GONE);
|
||||
}
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
switchCompatNotify.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
// Save the state here
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.SET_NOTIFY, isChecked);
|
||||
editor.putBoolean(Helper.SET_ALLOW_NOTIFICATION, isChecked);
|
||||
editor.apply();
|
||||
/*if (isChecked) {
|
||||
if (isChecked) {
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
PushHelper.startStreaming(SettingsActivity.this);
|
||||
} else {
|
||||
notification_container.setVisibility(View.GONE);
|
||||
}*/
|
||||
PushHelper.startStreaming(SettingsActivity.this);
|
||||
new Thread(() -> {
|
||||
List<Account> accounts = new AccountDAO(SettingsActivity.this, db).getPushNotificationAccounts();
|
||||
runOnUiThread(() -> {
|
||||
for (Account ac : accounts) {
|
||||
new Registration().unregisterApp(SettingsActivity.this, ac.getUsername() + "@" + ac.getInstance());
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
//Cancel scheduled jobs
|
||||
Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(NOTIFICATION_REFRESH);
|
||||
if( jobRequests!= null && jobRequests.size() >0) {
|
||||
for (JobRequest jobRequest : jobRequests) {
|
||||
JobManager.instance().cancel(jobRequest.getJobId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||
String instance = sharedpreferences.getString(Helper.PREF_INSTANCE, Helper.getLiveInstance(getApplicationContext()));
|
||||
final Account account = new AccountDAO(getApplicationContext(), db).getUniqAccount(userId, instance);
|
||||
|
@ -416,7 +447,6 @@ public class SettingsActivity extends BaseActivity {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
boolean clear_cache_exit = sharedpreferences.getBoolean(Helper.SET_CLEAR_CACHE_EXIT, false);
|
||||
final SwitchCompat set_clear_cache_exit = findViewById(R.id.set_clear_cache_exit);
|
||||
set_clear_cache_exit.setChecked(clear_cache_exit);
|
||||
|
|
|
@ -359,26 +359,33 @@
|
|||
android:gravity="center" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!-- Choose stream -->
|
||||
<LinearLayout
|
||||
android:id="@+id/notification_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
android:orientation="vertical">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/set_live_type"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/set_live_type"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/set_live_type_indication"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/settings_option_margin"
|
||||
android:textColor="@color/mastodonC2" />
|
||||
</LinearLayout>
|
||||
<!-- Choose stream -->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/set_live_type_indication"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/settings_option_margin"
|
||||
android:textColor="@color/mastodonC2" />
|
||||
|
||||
|
||||
<!-- TRUNCATE LONG TOOTS -->
|
||||
|
|
|
@ -18,6 +18,7 @@ import android.content.Context;
|
|||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
@ -119,9 +120,9 @@ public class RetrieveSearchAsyncTask {
|
|||
|
||||
}
|
||||
|
||||
if (!tagsOnly)
|
||||
if (!tagsOnly) {
|
||||
apiResponse = api.search(query);
|
||||
else {
|
||||
} else {
|
||||
//search tags only
|
||||
apiResponse = api.search(query);
|
||||
SQLiteDatabase db = Sqlite.getInstance(contextReference.get().getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.os.Build;
|
|||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.SpannableString;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
@ -5321,7 +5322,18 @@ public class API {
|
|||
params.put("resolve", "true");
|
||||
try {
|
||||
HttpsConnection httpsConnection = new HttpsConnection(context, this.instance);
|
||||
String response = httpsConnection.get(getAbsoluteUr2l("/search"), 10, params, prefKeyOauthTokenT);
|
||||
String response;
|
||||
if (MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.PIXELFED) {
|
||||
response = httpsConnection.get(getAbsoluteUr2l("/search"), 10, params, prefKeyOauthTokenT);
|
||||
} else {
|
||||
String searchPixelfed;
|
||||
try {
|
||||
searchPixelfed = "q=" + URLEncoder.encode(query, "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
searchPixelfed = "q=" + query;
|
||||
}
|
||||
response = httpsConnection.get(Helper.getLiveInstanceWithProtocol(context) + "/api/search?" + searchPixelfed + "&src=metro&v=2&scope=all", 10, null, prefKeyOauthTokenT);
|
||||
}
|
||||
results = parseResultsResponse(new JSONObject(response));
|
||||
apiResponse.setResults(results);
|
||||
} catch (HttpsConnection.HttpsConnectionException e) {
|
||||
|
@ -6051,8 +6063,10 @@ public class API {
|
|||
if (resobj.has("statuses")) {
|
||||
results.setStatuses(parseStatuses(context, resobj.getJSONArray("statuses")));
|
||||
}
|
||||
results.setTrends(parseTrends(resobj.getJSONArray("hashtags")));
|
||||
results.setHashtags(parseTags(resobj.getJSONArray("hashtags")));
|
||||
if (resobj.has("hashtags") && !resobj.isNull("hashtags")) {
|
||||
results.setTrends(parseTrends(resobj.getJSONArray("hashtags")));
|
||||
results.setHashtags(parseTags(resobj.getJSONArray("hashtags")));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
}
|
||||
|
@ -6575,6 +6589,7 @@ public class API {
|
|||
}
|
||||
} catch (JSONException e) {
|
||||
setDefaultError(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return accounts;
|
||||
}
|
||||
|
@ -6598,6 +6613,7 @@ public class API {
|
|||
i++;
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
setDefaultError(e);
|
||||
}
|
||||
return accounts;
|
||||
|
|
|
@ -16,6 +16,7 @@ package app.fedilab.android.fragments;
|
|||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentUris;
|
||||
|
@ -57,9 +58,12 @@ import androidx.appcompat.widget.SwitchCompat;
|
|||
import androidx.fragment.app.Fragment;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
|
||||
import com.evernote.android.job.JobManager;
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.unifiedpush.android.connector.Registration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -111,6 +115,7 @@ import static app.fedilab.android.fragments.ContentSettingsFragment.type.MENU;
|
|||
import static app.fedilab.android.fragments.ContentSettingsFragment.type.NOTIFICATIONS;
|
||||
import static app.fedilab.android.fragments.ContentSettingsFragment.type.PRIVACY;
|
||||
import static app.fedilab.android.fragments.ContentSettingsFragment.type.TIMELINES;
|
||||
import static app.fedilab.android.jobs.BaseNotificationsSyncJob.NOTIFICATION_REFRESH;
|
||||
|
||||
public class ContentSettingsFragment extends Fragment implements OnRetrieveRemoteAccountInterface, OnRetrieveRelationshipInterface {
|
||||
|
||||
|
@ -895,27 +900,44 @@ public class ContentSettingsFragment extends Fragment implements OnRetrieveRemot
|
|||
}
|
||||
|
||||
|
||||
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_PUSH_NOTIFICATIONS, true);
|
||||
boolean notify = sharedpreferences.getBoolean(Helper.SET_ALLOW_NOTIFICATION, true);
|
||||
final SwitchCompat switchCompatNotify = rootView.findViewById(R.id.set_notify);
|
||||
switchCompatNotify.setChecked(notify);
|
||||
final LinearLayout notification_container = rootView.findViewById(R.id.notification_container);
|
||||
if (notify) {
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
|
||||
} else {
|
||||
notification_container.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
switchCompatNotify.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
// Save the state here
|
||||
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||
editor.putBoolean(Helper.SET_PUSH_NOTIFICATIONS, isChecked);
|
||||
editor.putBoolean(Helper.SET_ALLOW_NOTIFICATION, isChecked);
|
||||
editor.apply();
|
||||
if (isChecked) {
|
||||
notification_container.setVisibility(View.VISIBLE);
|
||||
PushHelper.startStreaming(context);
|
||||
} else {
|
||||
notification_container.setVisibility(View.GONE);
|
||||
new Thread(() -> {
|
||||
List<Account> accounts = new AccountDAO(context, db).getPushNotificationAccounts();
|
||||
((Activity) context).runOnUiThread(() -> {
|
||||
for (Account ac : accounts) {
|
||||
new Registration().unregisterApp(context, ac.getUsername() + "@" + ac.getInstance());
|
||||
}
|
||||
});
|
||||
}).start();
|
||||
//Cancel scheduled jobs
|
||||
Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(NOTIFICATION_REFRESH);
|
||||
if (jobRequests != null && jobRequests.size() > 0) {
|
||||
for (JobRequest jobRequest : jobRequests) {
|
||||
JobManager.instance().cancel(jobRequest.getJobId());
|
||||
}
|
||||
}
|
||||
}
|
||||
PushHelper.startStreaming(context);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -349,6 +349,7 @@ public class BaseHelper {
|
|||
public static final String SET_SHOW_REPLIES = "set_show_replies";
|
||||
public static final String SET_VIDEO_NSFW = "set_video_nsfw";
|
||||
public static final String SET_PUSH_NOTIFICATIONS = "set_push_notifications";
|
||||
public static final String SET_ALLOW_NOTIFICATION = "set_allow_notification";
|
||||
public static final String SET_DISABLE_GIF = "set_disable_gif";
|
||||
public static final String SET_DISABLE_ANIMATED_EMOJI = "set_disable_animated_emoji";
|
||||
public static final String SET_CAPITALIZE = "set_capitalize";
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import org.unifiedpush.android.connector.Registration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import app.fedilab.android.R;
|
||||
import app.fedilab.android.client.Entities.Account;
|
||||
|
@ -26,12 +27,16 @@ import static android.content.Context.MODE_PRIVATE;
|
|||
import static app.fedilab.android.helper.BaseHelper.NOTIF_NONE;
|
||||
import static app.fedilab.android.helper.BaseHelper.NOTIF_PUSH;
|
||||
import static app.fedilab.android.helper.BaseHelper.liveNotifType;
|
||||
import static app.fedilab.android.jobs.BaseNotificationsSyncJob.NOTIFICATION_REFRESH;
|
||||
|
||||
import com.evernote.android.job.JobManager;
|
||||
import com.evernote.android.job.JobRequest;
|
||||
|
||||
public class PushHelper {
|
||||
|
||||
public static void startStreaming(Context context) {
|
||||
int liveNotifications = liveNotifType(context);
|
||||
ApplicationJob.cancelAllJob(NotificationsSyncJob.NOTIFICATION_REFRESH);
|
||||
ApplicationJob.cancelAllJob(NOTIFICATION_REFRESH);
|
||||
NotificationsSyncJob.schedule(false);
|
||||
switch (liveNotifications) {
|
||||
case NOTIF_PUSH:
|
||||
|
@ -44,6 +49,13 @@ public class PushHelper {
|
|||
}
|
||||
});
|
||||
}).start();
|
||||
//Cancel scheduled jobs
|
||||
Set<JobRequest> jobRequests = JobManager.instance().getAllJobRequestsForTag(NOTIFICATION_REFRESH);
|
||||
if (jobRequests != null && jobRequests.size() > 0) {
|
||||
for (JobRequest jobRequest : jobRequests) {
|
||||
JobManager.instance().cancel(jobRequest.getJobId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case NOTIF_NONE:
|
||||
new Thread(() -> {
|
||||
|
@ -55,6 +67,7 @@ public class PushHelper {
|
|||
}
|
||||
});
|
||||
}).start();
|
||||
NotificationsSyncJob.schedule(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue