<commit_before>package com.movim.movim;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.webkit.JavascriptInterface;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
    private WebView webview;
    private ProgressBar progressbar;
    private Integer counter = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        webview = (WebView) findViewById(R.id.webview);

        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);
        webview.getSettings().setMixedContentMode(0);

        progressbar = (ProgressBar) findViewById(R.id.progress);
        progressbar.setIndeterminate(true);

        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setStatusBarColor(Color.rgb(48, 63, 159));
        }

        webview.addJavascriptInterface(this, "Android");

        webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                progressbar.setProgress(progress);
                if (progress < 100 && progress > 0 && progressbar.getVisibility() == ProgressBar.GONE) {
                    progressbar.setIndeterminate(true);
                    progressbar.setVisibility(ProgressBar.VISIBLE);
                }
                if (progress == 100) {
                    progressbar.setVisibility(ProgressBar.GONE);
                }

            }

        });
        webview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                webview.loadUrl("file:///android_asset/error.html");
            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                String origin = Uri.parse(view.getUrl()).getHost();
                String aim = Uri.parse(url).getHost();

                if (origin.isEmpty() || origin.equals(aim)) {
                    return false;
                } else {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
            }

            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                handler.proceed(); // Ignore SSL certificate errors
            }
        });

        webview.loadUrl("file:///android_asset/index.html");

        onNewIntent(getIntent());
    }

    @Override
    public void onNewIntent(Intent intent){
        Bundle b = intent.getExtras();

        if(b != null) {
            this.counter = 0;
            String action = (String) b.get("url");
            System.out.println("url" + action);
            webview.loadUrl(action);
        }
    }

    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
    }
    @JavascriptInterface
    public void showNotification(String title, String body, String picture, String action) {
        Bitmap pictureBitmap = getBitmapFromURL(picture);
        Intent i = new Intent(this, MainActivity.class);

        if(action != null) {
            i.putExtra("url", action);
            i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }

        PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

        this.counter++;

        //Drawable d = getPackageManager().getApplicationIcon(getApplicationInfo());
        Notification notification = new Notification.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_name)
                .setLargeIcon(pictureBitmap)
                .setContentTitle(title)
                .setContentText(body)
                .setContentIntent(pi)
                .setAutoCancel(true)
                .setColor(Color.parseColor("#3F51B5"))
                .setNumber(this.counter)
                .build();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(0, notification);
    }<commit_msg>Improve the notification system<commit_after>package com.movim.movim;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.SslErrorHandler;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.webkit.JavascriptInterface;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@SuppressLint("SetJavaScriptEnabled")
public class MainActivity extends Activity {
    private WebView webview;
    private ProgressBar progressbar;
    private HashMap<String, List<String>> notifs;
    private static final String NOTIFICATION_DELETED_ACTION = "NOTIFICATION_DELETED";
    private static MainActivity instance;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        this.notifs = new HashMap<String, List<String>>();

        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        webview = (WebView) findViewById(R.id.webview);

        webview.getSettings().setJavaScriptEnabled(true);
        webview.getSettings().setDomStorageEnabled(true);
        webview.getSettings().setMixedContentMode(0);

        progressbar = (ProgressBar) findViewById(R.id.progress);
        progressbar.setIndeterminate(true);

        if (Build.VERSION.SDK_INT >= 21) {
            getWindow().setStatusBarColor(Color.rgb(48, 63, 159));
        }

        webview.addJavascriptInterface(this, "Android");

        webview.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                progressbar.setProgress(progress);
                if (progress < 100 && progress > 0 && progressbar.getVisibility() == ProgressBar.GONE) {
                    progressbar.setIndeterminate(true);
                    progressbar.setVisibility(ProgressBar.VISIBLE);
                }
                if (progress == 100) {
                    progressbar.setVisibility(ProgressBar.GONE);
                }

            }

        });
        webview.setWebViewClient(new WebViewClient() {
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                webview.loadUrl("file:///android_asset/error.html");
            }

            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                String origin = Uri.parse(view.getUrl()).getHost();
                String aim = Uri.parse(url).getHost();

                if (origin.isEmpty() || origin.equals(aim)) {
                    return false;
                } else {
                    Intent intent = new Intent(Intent.ACTION_VIEW);
                    intent.setData(Uri.parse(url));
                    startActivity(intent);
                    return true;
                }
            }

            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                handler.proceed(); // Ignore SSL certificate errors
            }
        });

        webview.loadUrl("file:///android_asset/index.html");

        onNewIntent(getIntent());

        instance = this;
    }

    @Override
    public void onNewIntent(Intent intent){
        Bundle b = intent.getExtras();
        String action = intent.getAction();
        if(b != null) {
            if (action != null && action.equals("notification_cancelled")) {
                String key = (String) b.get("url");
                this.notifs.remove(key);
            } else {
                String url = (String) b.get("url");
                webview.loadUrl(url);
            }
        }
    }

    public static MainActivity getInstance(){
        return instance;
    }

    @JavascriptInterface
    public void showToast(String toast) {
        Toast.makeText(this, toast, Toast.LENGTH_SHORT).show();
    }
    @JavascriptInterface
    public void showNotification(String title, String body, String picture, String action) {
        Bitmap pictureBitmap = getBitmapFromURL(picture);

        Intent i = new Intent(this, MainActivity.class);
        if(action != null) {
            i.putExtra("url", action);
            i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        }
        PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

        // The deleteIntent declaration
        Intent deleteIntent = new Intent(NOTIFICATION_DELETED_ACTION);
        if(action != null) {
            deleteIntent.putExtra("url", action);
        }
        PendingIntent pendingDeleteIntent = PendingIntent.getBroadcast(this, 0, deleteIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        registerReceiver(receiver, new IntentFilter(NOTIFICATION_DELETED_ACTION));

        //Integer counter;
        List<String> messages = null;

        // There is already pending notifications
        if(this.notifs.get(action) != null) {
            messages = this.notifs.get(action);
        } else {
            messages = new ArrayList<String>();
        }

        messages.add(body);

        if(messages.size() > 5) {
            messages.remove(0);
        }

        this.notifs.put(action, messages);

        // We create the inbox
        Notification.InboxStyle style = new Notification.InboxStyle();
        for (int j = 0; j < messages.size(); j++) {
            style.addLine(messages.get(j));
        }

        style.setBigContentTitle(title);

        Notification notification = new Notification.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_name)
                .setLargeIcon(pictureBitmap)
                .setContentTitle(title)
                .setContentText(body)
                .setContentIntent(pi)
                .setDeleteIntent(pendingDeleteIntent)
                .setAutoCancel(true)
                .setColor(Color.parseColor("#3F51B5"))
                .setNumber(messages.size())
                .setStyle(style)
                .setGroup("movim")
                .build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(action, 0, notification);
    }

    private final BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle b = intent.getExtras();
            if(b != null) {
                String key = (String) b.get("url");
                MainActivity.getInstance().notifs.remove(key);
            }

            unregisterReceiver(this);
        }
    };
{'fraction_non_alphanumeric': 0.10050054747379947, 'fraction_numerical': 0.004066948224620679, 'mean_word_length': 2.460622462787551, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4807768', 'n_tokens_mistral': 3491, 'n_tokens_neox': 3274, 'n_words': 643}