├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ └── ic_launcher.jpg │ │ │ ├── mipmap-mdpi │ │ │ │ └── ic_launcher.jpg │ │ │ ├── mipmap-xhdpi │ │ │ │ └── ic_launcher.jpg │ │ │ ├── mipmap-xxhdpi │ │ │ │ └── ic_launcher.jpg │ │ │ ├── mipmap-xxxhdpi │ │ │ │ └── ic_launcher.jpg │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.xml │ │ │ ├── menu │ │ │ │ └── menu.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ ├── activity_main.xml │ │ │ │ └── recycler_notification_item.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── pushbots │ │ │ │ └── notificationshistory │ │ │ │ ├── utils │ │ │ │ └── Constants.java │ │ │ │ ├── MyApplication.java │ │ │ │ ├── storage │ │ │ │ ├── DatabaseContract.java │ │ │ │ └── Database.java │ │ │ │ ├── model │ │ │ │ └── PushBotsModel.java │ │ │ │ ├── adapter │ │ │ │ └── NotificationAdapter.java │ │ │ │ ├── activities │ │ │ │ └── MainActivity.java │ │ │ │ └── CustomHandler.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── pushbots │ │ │ └── notificationshistory │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── pushbots │ │ └── notificationshistory │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── README.md ├── .idea ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | "# notification-history-android" 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pushbots/notification-history-android/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pushbots/notification-history-android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pushbots/notification-history-android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pushbots/notification-history-android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pushbots/notification-history-android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.jpg -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pushbots/notification-history-android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | NotificationsHistory 3 | Clear Notifications 4 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/utils/Constants.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory.utils; 2 | 3 | /** 4 | * Created by Muhammad on 1/17/2017. 5 | */ 6 | 7 | public final class Constants { 8 | 9 | public static String SENT_TIME = "google.sent_time"; 10 | public static String NOTIFICATION_ID = "pb_n_id"; 11 | public static String MESSAGE = "message"; 12 | public static int DELAY_TIME = 2000; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/MyApplication.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory; 2 | 3 | import android.app.Application; 4 | 5 | import com.pushbots.push.Pushbots; 6 | 7 | /** 8 | * Created by Muhammad on 1/17/2017. 9 | */ 10 | 11 | public class MyApplication extends Application { 12 | 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | Pushbots.sharedInstance().init(this); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/test/java/com/pushbots/notificationshistory/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in H:\SDK/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/pushbots/notificationshistory/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.pushbots.notificationshistory", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/storage/DatabaseContract.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory.storage; 2 | 3 | import android.provider.BaseColumns; 4 | 5 | /** 6 | * Created by Muhammad on 9/27/2016. 7 | */ 8 | 9 | public final class DatabaseContract { 10 | // To prevent someone from accidentally instantiating the contract class, 11 | // make the constructor private. 12 | private DatabaseContract() {} 13 | 14 | /* Inner class that defines the table contents */ 15 | public static class DataEntry implements BaseColumns { 16 | public static final String TABLE_NAME = "notifications"; 17 | public static final String COLUMN_INDEX = "index"; 18 | public static final String COLUMN_NOTIFICATION_ID = "nID"; 19 | public static final String COLUMN_MESSAGE = "message"; 20 | public static final String COLUMN_DATE= "sent_time"; 21 | 22 | 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recycler_notification_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 13 | 14 | 17 | 18 | 28 | 29 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.0" 6 | defaultConfig { 7 | applicationId "com.pushbots.notificationshistory" 8 | manifestPlaceholders = [manifestApplicationId : "${applicationId}", 9 | pushbots_app_id : "585a7cba4a9efa10fb8b4570", 10 | pushbots_loglevel : "DEBUG", 11 | google_sender_id : "332366247830"] 12 | minSdkVersion 14 13 | targetSdkVersion 25 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:25.1.0' 32 | testCompile 'junit:junit:4.12' 33 | compile 'com.google.android.gms:play-services-gcm:+' 34 | compile 'com.pushbots:pushbots-lib:3.0.1@aar' 35 | compile 'com.android.support:recyclerview-v7:25.1.0' 36 | compile 'com.android.support:cardview-v7:25.1.0' 37 | compile 'com.android.support:design:25.1.0' 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/model/PushBotsModel.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | /** 7 | * Created by Muhammad on 1/17/2017. 8 | */ 9 | 10 | public class PushBotsModel implements Parcelable { 11 | private String date; 12 | 13 | public PushBotsModel() { 14 | 15 | } 16 | 17 | protected PushBotsModel(Parcel in) { 18 | date = in.readString(); 19 | message = in.readString(); 20 | notificationID = in.readString(); 21 | } 22 | 23 | @Override 24 | public void writeToParcel(Parcel dest, int flags) { 25 | dest.writeString(date); 26 | dest.writeString(message); 27 | dest.writeString(notificationID); 28 | } 29 | 30 | @Override 31 | public int describeContents() { 32 | return 0; 33 | } 34 | 35 | public static final Creator CREATOR = new Creator() { 36 | @Override 37 | public PushBotsModel createFromParcel(Parcel in) { 38 | return new PushBotsModel(in); 39 | } 40 | 41 | @Override 42 | public PushBotsModel[] newArray(int size) { 43 | return new PushBotsModel[size]; 44 | } 45 | }; 46 | 47 | public String getDate() { 48 | return date; 49 | } 50 | 51 | public void setDate(String date) { 52 | this.date = date; 53 | } 54 | 55 | public String getMessage() { 56 | return message; 57 | } 58 | 59 | public void setMessage(String message) { 60 | this.message = message; 61 | } 62 | 63 | public String getNotificationID() { 64 | return notificationID; 65 | } 66 | 67 | public void setNotificationID(String notificationID) { 68 | this.notificationID = notificationID; 69 | } 70 | 71 | private String message; 72 | private String notificationID; 73 | 74 | 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/adapter/NotificationAdapter.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.CardView; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.pushbots.notificationshistory.R; 13 | import com.pushbots.notificationshistory.model.PushBotsModel; 14 | 15 | import java.util.ArrayList; 16 | 17 | /** 18 | * Created by Muhammad on 1/17/2017. 19 | */ 20 | 21 | public class NotificationAdapter extends RecyclerView.Adapter { 22 | ArrayList pushBotsModels; 23 | Context context; 24 | 25 | public NotificationAdapter(Context context, ArrayList pushBotsModels) { 26 | this.pushBotsModels = pushBotsModels; 27 | this.context = context; 28 | } 29 | 30 | @Override 31 | public NotificationAdapter.NotificationsHistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) { 32 | View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_notification_item, parent, false); 33 | NotificationsHistoryHolder notificationsHistoryHolder = new NotificationsHistoryHolder(v); 34 | return notificationsHistoryHolder; 35 | } 36 | 37 | @Override 38 | public void onBindViewHolder(NotificationsHistoryHolder holder, int position) { 39 | try { 40 | holder.itemName.setText(pushBotsModels.get(position).getMessage()); 41 | } catch (Exception e) { 42 | e.printStackTrace(); 43 | } 44 | } 45 | 46 | @Override 47 | public int getItemCount() { 48 | return pushBotsModels.size(); 49 | } 50 | 51 | 52 | public static class NotificationsHistoryHolder extends RecyclerView.ViewHolder { 53 | TextView itemName; 54 | ImageView imageView; 55 | CardView cardView; 56 | 57 | public NotificationsHistoryHolder(View itemView) { 58 | super(itemView); 59 | itemName = (TextView) itemView.findViewById(R.id.itemName); 60 | imageView = (ImageView) itemView.findViewById(R.id.notificationImage); 61 | cardView = (CardView) itemView.findViewById(R.id.card_view); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.8 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/activities/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory.activities; 2 | 3 | import android.os.Bundle; 4 | import android.os.Handler; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.support.v7.widget.LinearLayoutManager; 8 | import android.support.v7.widget.RecyclerView; 9 | import android.view.Menu; 10 | import android.view.MenuItem; 11 | 12 | import com.pushbots.notificationshistory.CustomHandler; 13 | import com.pushbots.notificationshistory.R; 14 | import com.pushbots.notificationshistory.adapter.NotificationAdapter; 15 | import com.pushbots.notificationshistory.storage.Database; 16 | import com.pushbots.notificationshistory.utils.Constants; 17 | import com.pushbots.push.Pushbots; 18 | 19 | public class MainActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener { 20 | RecyclerView notificationsRecycler; 21 | Database database; 22 | SwipeRefreshLayout swipeRefreshLayout; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main); 28 | notificationsRecycler = (RecyclerView) findViewById(R.id.notificationsRecycler); 29 | swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); 30 | swipeRefreshLayout.setOnRefreshListener(this); 31 | notificationsRecycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); 32 | notificationsRecycler.setHasFixedSize(true); 33 | Pushbots.sharedInstance().setCustomHandler(CustomHandler.class); 34 | Pushbots.sharedInstance().registerForRemoteNotifications(); 35 | } 36 | 37 | @Override 38 | protected void onStart() { 39 | super.onStart(); 40 | database = new Database(this); 41 | swipeRefreshLayout.setRefreshing(true); 42 | fillNotificationsData(); 43 | Handler handler = new Handler(); 44 | handler.postDelayed(new Runnable() { 45 | @Override 46 | public void run() { 47 | swipeRefreshLayout.setRefreshing(false); 48 | } 49 | }, Constants.DELAY_TIME); 50 | } 51 | 52 | @Override 53 | public boolean onCreateOptionsMenu(Menu menu) { 54 | getMenuInflater().inflate(R.menu.menu, menu); 55 | return true; 56 | } 57 | 58 | @Override 59 | public boolean onOptionsItemSelected(MenuItem item) { 60 | switch (item.getItemId()) { 61 | case android.R.id.home: 62 | onBackPressed(); 63 | return true; 64 | case R.id.delete: 65 | database.deleteNotifications(); 66 | fillNotificationsData(); 67 | return true; 68 | default: 69 | return super.onOptionsItemSelected(item); 70 | } 71 | } 72 | 73 | @Override 74 | public void onRefresh() { 75 | fillNotificationsData(); 76 | } 77 | 78 | private void fillNotificationsData() { 79 | NotificationAdapter notificationAdapter = new NotificationAdapter(this, database.readNotificationData()); 80 | notificationAdapter.notifyDataSetChanged(); 81 | notificationsRecycler.setAdapter(notificationAdapter); 82 | swipeRefreshLayout.setRefreshing(false); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/CustomHandler.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | 10 | import com.pushbots.notificationshistory.storage.Database; 11 | import com.pushbots.push.Pushbots; 12 | import com.pushbots.push.utils.PBConstants; 13 | 14 | /** 15 | * Created by Muhammad on 1/17/2017. 16 | */ 17 | 18 | public class CustomHandler extends BroadcastReceiver { 19 | private String TAG = "PB3"; 20 | 21 | @Override 22 | public void onReceive(Context context, Intent intent) { 23 | String action = intent.getAction(); 24 | Log.d(TAG, "action=" + action); 25 | if (action.equals(PBConstants.EVENT_MSG_RECEIVE)) { 26 | Database database = new Database(context); 27 | database.insertNotificationData(intent.getBundleExtra(PBConstants.EVENT_MSG_RECEIVE)); 28 | Log.e("image", intent.getBundleExtra(PBConstants.EVENT_MSG_RECEIVE).getString("image")); 29 | } 30 | // Handle Push Message when opened 31 | if (action.equals(PBConstants.EVENT_MSG_OPEN)) { 32 | 33 | 34 | //Bundle containing all fields of the opened notification 35 | Bundle bundle = intent.getExtras().getBundle(PBConstants.EVENT_MSG_OPEN); 36 | 37 | //Record opened notification 38 | Pushbots.PushNotificationOpened(context, bundle); 39 | 40 | Log.i(TAG, "User clicked notification with Message: " + bundle.get("message")); 41 | 42 | //Get Custom field key e.g. article_id 43 | if (bundle.get("article_id") != null) 44 | Log.i(TAG, "Article Id: " + bundle.get("article_id")); 45 | 46 | //Start Launch Activity 47 | String packageName = context.getPackageName(); 48 | Intent resultIntent = new Intent(context.getPackageManager().getLaunchIntentForPackage(packageName)); 49 | resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 50 | 51 | // Check for next activity 52 | String next_activity = bundle.getString("nextActivity"); 53 | if (null != next_activity) { 54 | try { 55 | Log.i(TAG, "Opening Custom Activity " + next_activity); 56 | resultIntent = new Intent(context, Class.forName(next_activity)); 57 | resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 58 | } catch (ClassNotFoundException e) { 59 | //ClassNotFound 60 | e.printStackTrace(); 61 | } 62 | } 63 | 64 | // Check for open URL 65 | String open_url = bundle.getString("openURL"); 66 | if (null != open_url && (open_url.startsWith("http://") || open_url.startsWith("https://"))) { 67 | resultIntent = new Intent("android.intent.action.VIEW", Uri.parse(open_url)); 68 | resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 69 | Log.d(TAG, "Opening url: " + open_url); 70 | } 71 | 72 | resultIntent.putExtras(intent.getBundleExtra("pushData")); 73 | 74 | //Open activity or URL with pushData. 75 | if (null != resultIntent) { 76 | context.startActivity(resultIntent); 77 | } 78 | 79 | } else if (action.equals(PBConstants.EVENT_MSG_RECEIVE)) { 80 | 81 | //Bundle containing all fields of the notification 82 | Bundle bundle = intent.getExtras().getBundle(PBConstants.EVENT_MSG_RECEIVE); 83 | Log.i(TAG, "User received notification with Message: " + bundle.get("message")); 84 | 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/java/com/pushbots/notificationshistory/storage/Database.java: -------------------------------------------------------------------------------- 1 | package com.pushbots.notificationshistory.storage; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | 11 | import com.pushbots.notificationshistory.model.PushBotsModel; 12 | import com.pushbots.notificationshistory.utils.Constants; 13 | 14 | import java.util.ArrayList; 15 | 16 | import static com.pushbots.notificationshistory.storage.DatabaseContract.DataEntry.COLUMN_DATE; 17 | 18 | /** 19 | * Created by Muhammad on 9/27/2016. 20 | */ 21 | 22 | public class Database extends SQLiteOpenHelper { 23 | private ArrayList pushBotsModels; 24 | private static final int DATABASE_VERSION = 1; 25 | private static final String DATABASE_NAME = "PushBots.db"; 26 | private static final String TEXT_TYPE = " TEXT"; 27 | private static final String COMMA_SEP = ","; 28 | private static final String SQL_CREATE_ENTRIES = 29 | "CREATE TABLE " + DatabaseContract.DataEntry.TABLE_NAME + " (" + 30 | DatabaseContract.DataEntry._ID + " INTEGER PRIMARY KEY" + 31 | COMMA_SEP + 32 | DatabaseContract.DataEntry.COLUMN_MESSAGE + TEXT_TYPE + 33 | COMMA_SEP + 34 | COLUMN_DATE + TEXT_TYPE + 35 | COMMA_SEP + 36 | DatabaseContract.DataEntry.COLUMN_NOTIFICATION_ID + TEXT_TYPE + " )"; 37 | 38 | private static final String SQL_DELETE_ENTRIES = 39 | "DROP TABLE IF EXISTS " + DatabaseContract.DataEntry.TABLE_NAME; 40 | 41 | 42 | public Database(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { 43 | super(context, name, factory, version); 44 | } 45 | 46 | public Database(Context context) { 47 | super(context, DATABASE_NAME, null, DATABASE_VERSION); 48 | pushBotsModels = new ArrayList<>(); 49 | } 50 | 51 | @Override 52 | public void onCreate(SQLiteDatabase sqLiteDatabase) { 53 | Log.e("database", SQL_CREATE_ENTRIES); 54 | sqLiteDatabase.execSQL(SQL_CREATE_ENTRIES); 55 | } 56 | 57 | @Override 58 | public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { 59 | 60 | } 61 | 62 | @Override 63 | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { 64 | onUpgrade(db, oldVersion, newVersion); 65 | 66 | } 67 | 68 | Cursor cursor; 69 | 70 | private int getCursorSize() { 71 | try { 72 | SQLiteDatabase db = this.getReadableDatabase(); 73 | String sortOrder = 74 | DatabaseContract.DataEntry._ID + " DESC"; 75 | 76 | cursor = db.query( 77 | DatabaseContract.DataEntry.TABLE_NAME, // The table to query 78 | null, // The columns to return 79 | null, // The columns for the WHERE clause 80 | null, // The values for the WHERE clause 81 | null, // don't group the rows 82 | null, // don't filter by row groups 83 | sortOrder // The sort order 84 | ); 85 | cursor.moveToFirst(); 86 | 87 | return cursor.getCount(); 88 | } catch (Exception e) { 89 | e.printStackTrace(); 90 | return cursor.getCount(); 91 | } 92 | } 93 | 94 | public ArrayList readNotificationData() { 95 | try { 96 | pushBotsModels.clear(); 97 | SQLiteDatabase db = this.getReadableDatabase(); 98 | 99 | // Define a projection that specifies which columns from the database 100 | // you will actually use after this query. 101 | String[] projection = { 102 | DatabaseContract.DataEntry._ID, 103 | DatabaseContract.DataEntry.COLUMN_MESSAGE, 104 | DatabaseContract.DataEntry.COLUMN_DATE, 105 | DatabaseContract.DataEntry.COLUMN_NOTIFICATION_ID 106 | }; 107 | 108 | // Filter results WHERE "title" = 'My Title' 109 | String selection = DatabaseContract.DataEntry._ID + " = ?"; 110 | String[] selectionArgs = {"My Title"}; 111 | 112 | // How you want the results sorted in the resulting Cursor 113 | String sortOrder = 114 | DatabaseContract.DataEntry._ID + " DESC"; 115 | 116 | Cursor c = db.query( 117 | DatabaseContract.DataEntry.TABLE_NAME, // The table to query 118 | projection, // The columns to return 119 | null, // The columns for the WHERE clause 120 | null, // The values for the WHERE clause 121 | null, // don't group the rows 122 | null, // don't filter by row groups 123 | sortOrder // The sort order 124 | ); 125 | c.moveToFirst(); 126 | 127 | String[] str = new String[getCursorSize()]; 128 | if (c.moveToFirst()) { 129 | while (!c.isAfterLast()) { 130 | addDataForRead(c); 131 | c.moveToNext(); 132 | } 133 | } 134 | c.close(); 135 | db.close(); 136 | return pushBotsModels; 137 | } catch (Exception e) { 138 | e.printStackTrace(); 139 | return null; 140 | } 141 | } 142 | 143 | public void insertNotificationData(Bundle bundle) { 144 | 145 | try { 146 | SQLiteDatabase db = this.getWritableDatabase(); 147 | ContentValues values = new ContentValues(); 148 | values.put(DatabaseContract.DataEntry.COLUMN_NOTIFICATION_ID, bundle.getString(Constants.NOTIFICATION_ID, "")); 149 | values.put(DatabaseContract.DataEntry.COLUMN_MESSAGE, bundle.getString(Constants.MESSAGE, "")); 150 | values.put(COLUMN_DATE, bundle.getLong(Constants.SENT_TIME, 0)); 151 | // Insert the new row, returning the primary key value of the new row 152 | db.insert(DatabaseContract.DataEntry.TABLE_NAME, null, values); 153 | db.close(); 154 | } catch (Exception e) { 155 | e.printStackTrace(); 156 | } 157 | } 158 | 159 | public void deleteNotifications() { 160 | SQLiteDatabase db = this.getWritableDatabase(); 161 | // Define 'where' part of query. 162 | String selection = (DatabaseContract.DataEntry.COLUMN_MESSAGE + " LIKE ?"); 163 | // Specify arguments in placeholder order. 164 | String[] selectionArgs = {"MyTitle"}; 165 | // Issue SQL statement. 166 | db.delete(DatabaseContract.DataEntry.TABLE_NAME, null, null); 167 | 168 | } 169 | 170 | private void addDataForRead(Cursor c) { 171 | PushBotsModel notificationsDatabaseModel = new PushBotsModel(); 172 | notificationsDatabaseModel.setDate(c.getString(c.getColumnIndexOrThrow(COLUMN_DATE))); 173 | notificationsDatabaseModel.setMessage(c.getString(c.getColumnIndexOrThrow(DatabaseContract.DataEntry.COLUMN_MESSAGE))); 174 | 175 | notificationsDatabaseModel.setNotificationID(c.getString(c.getColumnIndexOrThrow(DatabaseContract.DataEntry.COLUMN_NOTIFICATION_ID))); 176 | pushBotsModels.add(notificationsDatabaseModel); 177 | } 178 | } 179 | --------------------------------------------------------------------------------