commit 993ffaf8f9d147de9b0abde13ed220988c5370f3 Author: S1m Date: Mon Nov 22 09:27:58 2021 +0100 Init Working SSE diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..34477c7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: +- package-ecosystem: gradle + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..8217f3d --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,38 @@ + +on: [push, pull_request] + +name: Build + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: 11 + - run: ./gradlew build --stacktrace + - uses: actions/upload-artifact@v2 + with: + name: build + path: app/build/outputs/apk/debug/app-debug.apk + - if: startsWith(github.ref, 'refs/tags/') + run: | + cd app/build/outputs/apk/release + echo $RELEASE_KEY | base64 -d > release-key.jks + jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore release-key.jks -storepass $STOREPASS -keypass $KEYPASS app-release-unsigned.apk nextpush + jarsigner -verify app-release-unsigned.apk + sudo apt-get install zipalign -y + zipalign -v 4 app-release-unsigned.apk nextpush.apk + env: + RELEASE_KEY: ${{ secrets.RELEASE_KEY }} + KEYPASS: ${{ secrets.KEYPASS }} + STOREPASS: ${{ secrets.STOREPASS }} + - if: startsWith(github.ref, 'refs/tags/') + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: app/build/outputs/apk/release/nextpush.apk + tag: ${{ github.ref }} + overwrite: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..d77468e --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,68 @@ +plugins { + id 'com.android.application' + id 'kotlin-android' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + configurations.all { + resolutionStrategy { + force 'androidx.core:core-ktx:1.6.0' + force 'androidx.core:core:1.6.0' + } + } + + defaultConfig { + applicationId "org.unifiedpush.distributor.nextpush" + minSdkVersion 24 + targetSdkVersion 30 + versionCode 1 + versionName "0.0.1" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + resValue "string", "app_name", "NextPush" + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + debug { + resValue "string", "app_name", "NextPush-dbg" + applicationIdSuffix ".debug" + debuggable true + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } + + packagingOptions { + exclude("META-INF/*") + } + +} + +dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.6.0' + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.1' + implementation 'androidx.navigation:navigation-ui-ktx:2.3.5' + implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5' + implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.1")) + implementation("com.squareup.okhttp3:okhttp") + implementation("com.squareup.okhttp3:logging-interceptor") + implementation("com.squareup.okhttp3:okhttp-sse") + implementation 'com.github.nextcloud:Android-SingleSignOn:0.6.0' + implementation "com.squareup.retrofit2:retrofit:2.9.0" + implementation "com.squareup.retrofit2:converter-gson:2.9.0" + implementation "com.squareup.retrofit2:adapter-rxjava2:2.9.0" +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -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 \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..318d8d0 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..307bed5 Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountUtils.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountUtils.kt new file mode 100644 index 0000000..bced86b --- /dev/null +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/account/AccountUtils.kt @@ -0,0 +1,61 @@ +package org.unifiedpush.distributor.nextpush.account + +import android.app.Activity +import android.content.Context +import android.util.Log +import com.nextcloud.android.sso.AccountImporter +import com.nextcloud.android.sso.exceptions.AndroidGetAccountsPermissionNotGranted +import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException +import com.nextcloud.android.sso.exceptions.NextcloudFilesAppNotInstalledException +import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException +import com.nextcloud.android.sso.helper.SingleAccountHelper +import com.nextcloud.android.sso.model.SingleSignOnAccount +import com.nextcloud.android.sso.ui.UiExceptionManager + +private const val TAG = "AccountUtils" + +const val PREF_NAME = "NextPush" +const val PREF_DEVICE_ID = "deviceId" + +lateinit var ssoAccount: SingleSignOnAccount + +fun isConnected(context: Context) : Boolean { + try { + ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context) + } catch (e: NextcloudFilesAppAccountNotFoundException) { + UiExceptionManager.showDialogForException(context, e) + } catch (e: NoCurrentAccountSelectedException) { + Log.d(TAG,"Device is not connected") + return false + } + return true +} + +fun connect(activity: Activity) { + try { + AccountImporter.pickNewAccount(activity) + } catch (e: NextcloudFilesAppNotInstalledException) { + UiExceptionManager.showDialogForException(activity, e) + } catch (e: AndroidGetAccountsPermissionNotGranted) { + UiExceptionManager.showDialogForException(activity, e) + } +} + +fun saveDeviceId(context: Context, deviceId: String) { + context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) + .edit() + .putString(PREF_DEVICE_ID, deviceId) + .commit() +} + +fun getDeviceId(context: Context) : String? { + return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) + .getString(PREF_DEVICE_ID,null) +} + +fun removeDeviceId(context: Context) { + context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) + .edit() + .remove(PREF_DEVICE_ID) + .commit() +} diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt new file mode 100644 index 0000000..287e209 --- /dev/null +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/activities/MainActivity.kt @@ -0,0 +1,220 @@ +package org.unifiedpush.distributor.nextpush.activities + +import android.content.Intent +import android.os.Build +import android.os.Bundle +import android.util.Log +import android.view.Menu +import android.view.MenuItem +import android.view.View +import android.widget.* +import androidx.appcompat.app.AppCompatActivity +import com.nextcloud.android.sso.AccountImporter +import com.nextcloud.android.sso.ui.UiExceptionManager +import org.unifiedpush.distributor.nextpush.services.StartService +import com.nextcloud.android.sso.AccountImporter.IAccountAccessGranted + +import com.nextcloud.android.sso.api.NextcloudAPI.ApiConnectedListener + +import com.nextcloud.android.sso.helper.SingleAccountHelper + +import com.nextcloud.android.sso.model.SingleSignOnAccount +import java.lang.Exception +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.view.isVisible +import com.nextcloud.android.sso.AccountImporter.clearAllAuthTokens +import com.nextcloud.android.sso.exceptions.* +import org.unifiedpush.distributor.nextpush.R +import org.unifiedpush.distributor.nextpush.account.isConnected +import org.unifiedpush.distributor.nextpush.account.connect +import org.unifiedpush.distributor.nextpush.account.ssoAccount +import org.unifiedpush.distributor.nextpush.api.ApiUtils +import org.unifiedpush.distributor.nextpush.distributor.sendUnregistered +import org.unifiedpush.distributor.nextpush.distributor.MessagingDatabase +import java.lang.String.format + +const val TAG = "NextPush-MainActivity" + +class MainActivity : AppCompatActivity() { + + private lateinit var listView : ListView + private var showLogout = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + setSupportActionBar(findViewById(R.id.toolbar)) + if (isConnected(this)) { + showMain() + } else { + findViewById