Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
plugins {
id 'com.android.application'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be an application. This needs to be configured as a library.
Refer to https://github.com/Codigami/CFAlertDialog/blob/master/cfalertdialog/build.gradle

id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
}

android {
compileSdk 33

defaultConfig {
applicationId "com.bulletin"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = 11
}
buildFeatures {
viewBinding true
}
}


ext {
appCompat='1.4.1'
materialDesign='1.6.0'
vectorDrawable='1.1.0'
multiDex='2.0.1'
jUnit='4.13.2'
runner='1.4.0'
playCore='1.10.3'
retrofit='2.9.0'
espressoCore='3.4.0'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:$appCompat"
implementation "com.google.android.material:material:$materialDesign"
implementation "androidx.vectordrawable:vectordrawable:$vectorDrawable"
implementation "androidx.multidex:multidex:$multiDex"
implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: [])
implementation 'androidx.databinding:viewbinding:7.4.0'
testImplementation "junit:junit:$jUnit"
androidTestImplementation "androidx.test:runner:$runner"
implementation "com.google.android.play:core:$playCore"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCore"

implementation "com.squareup.retrofit2:converter-gson:$retrofit"

implementation 'com.github.bumptech.glide:glide:4.13.2'
kapt 'com.github.bumptech.glide:compiler:4.13.2'

}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.bulletin

import androidx.test.platform.app.InstrumentationRegistry
//import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
//@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.example.bulletin", appContext.packageName)
}
}
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.bulletin">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="com.bulletin.BulletinApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
tools:targetApi="31">
<activity
android:name=".DefaultActivity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
29 changes: 29 additions & 0 deletions app/src/main/java/com/bulletin/BulletinApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.bulletin

import android.app.Application
import android.content.Context
import android.content.pm.PackageManager
import android.util.Log
import com.bulletin.utilities.GsonHelper
import com.google.gson.Gson

class BulletinApp : Application() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application class is not required for this.
Wherever context is required it needs to be passed in as parameter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have same thinking but we need to discuss.

private var gsonInstance: Gson? = null

companion object {
lateinit var shared: BulletinApp
private set

val applicationContext: Context
get() {
return shared.applicationContext
}
}

//Initializer
init {
shared = this
gsonInstance = GsonHelper.gsonInstance
}

}
86 changes: 86 additions & 0 deletions app/src/main/java/com/bulletin/BulletinDataStore.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.bulletin

import com.bulletin.extension.lastSeenVersion
import com.bulletin.models.BulletinInfo
import com.bulletin.models.BulletinItem
import com.bulletin.models.Version
import com.bulletin.utilities.AppStorageHelper
import com.bulletin.utilities.VersionUtil
import java.util.*


class BulletinDataStore {

var data: MutableList<BulletinInfo> = mutableListOf()
private set

fun registerVersionInfo11(version: Version, items: MutableList<HashMap<String, Any>>) {

val bulletinItems = ArrayList<BulletinItem>()
for (itemAttributes in items) {
val bulletinItem = BulletinItem.createBulletinItem(itemAttributes) ?: return continue
bulletinItems.add(bulletinItem)
}

registerVersionInfo(version, bulletinItems)
}

fun registerVersionInfo(version: Version, items: MutableList<BulletinItem>?) {

if (items == null || items.isEmpty()) {
return
}

// Create Bulletin Info Object
val bulletinInfo = BulletinInfo.init(version, items)

data.add(bulletinInfo)
Collections.sort(data, BulletinInfo.descendingSort)
}


fun getData(
fromNewVersion: Version?,
toOldVersion: Version?,
limit: Int? = null
): ArrayList<BulletinInfo> {
// val finalMap: MutableList<BulletinInfo> = mutableListOf()
val bulletinInfo = arrayListOf<BulletinInfo>()

if (fromNewVersion == null && toOldVersion == null && limit == null) {

bulletinInfo.addAll(data)
return bulletinInfo
} else if (fromNewVersion == null && toOldVersion == null && limit != null) {
bulletinInfo.addAll(data.take(limit))
return bulletinInfo
}

val sortedList = data.sortedWith(compareBy({
it.version.version
}))

for (indice in sortedList.indices) {

if (indice == 0) AppStorageHelper.shared.lastSeenVersion =
Version.init(sortedList[indice].version.version)
if (VersionUtil.versionCompare(
fromNewVersion?.version,
sortedList[indice].version.version
) >= 0
) {
bulletinInfo.add(sortedList[indice])
} else if (VersionUtil.versionCompare(
toOldVersion?.version,
sortedList[indice].version.version
) < 0
) {
bulletinInfo.add(sortedList[indice])
}

if (limit != null && bulletinInfo.size >= limit) break

}
return bulletinInfo
}
}
Loading