Added back-end code to filter out instagram posts with specified keywords

This commit is contained in:
zerrium 2021-03-18 12:40:05 +07:00
parent d24bcd1a76
commit 0a672476d9
2 changed files with 25 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import android.content.Intent;
import android.content.ServiceConnection;
import android.content.res.TypedArray;
import android.database.MatrixCursor;
import android.net.IpSecManager;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
@ -83,6 +84,7 @@ import awais.instagrabber.utils.TextUtils;
import awais.instagrabber.utils.Utils;
import awais.instagrabber.utils.emoji.EmojiParser;
import awais.instagrabber.viewmodels.AppStateViewModel;
import zerrium.FilterKeywords;
import static awais.instagrabber.utils.NavigationExtensions.setupWithNavController;
import static awais.instagrabber.utils.Utils.settingsHelper;
@ -174,6 +176,18 @@ public class MainActivity extends BaseLanguageActivity implements FragmentManage
});
initEmojiCompat();
// initDmService();
initZerriumFilter(); //to filter out junk instagram post
}
private void initZerriumFilter(){
boolean filter_result = false;
try{
filter_result = FilterKeywords.insert(getResources().getStringArray(R.array.filter_keyword));
}catch(Exception e){
Log.e(TAG, "initZerriumFilter: " + e);
}
if(!filter_result) Log.d(TAG, "ZerriumFilter insert failed");
else Log.d(TAG, "ZerriumFilter insert success");
}
private void initDmService() {

View File

@ -1,6 +1,7 @@
package awais.instagrabber.adapters;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -27,6 +28,7 @@ import awais.instagrabber.models.PostsLayoutPreferences;
import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.repositories.responses.Caption;
import awais.instagrabber.repositories.responses.Media;
import zerrium.FilterKeywords;
public final class FeedAdapterV2 extends ListAdapter<Media, RecyclerView.ViewHolder> {
private static final String TAG = "FeedAdapterV2";
@ -152,6 +154,15 @@ public final class FeedAdapterV2 extends ListAdapter<Media, RecyclerView.ViewHol
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder viewHolder, final int position) {
final Media feedModel = getItem(position);
if (feedModel == null) return;
//Turn a junk (sponsored) instagram post from people we following into a blank post, I need help to improve this part
String c = feedModel.getCaption().getText();
if(FilterKeywords.filter(c)){
Log.d(TAG, "Filtered:\n" + c + "\n");
return;
}
//Zerrium (18 Mar 2021)
switch (layoutPreferences.getType()) {
case LINEAR:
((FeedItemViewHolder) viewHolder).bind(feedModel);