Skip to content

Commit

Permalink
Merge pull request #15 from Teknasyon-Teknoloji/feature/refactor
Browse files Browse the repository at this point in the history
Feature/refactor
  • Loading branch information
yasincetin002 authored Sep 1, 2021
2 parents 81c4a1c + 658c305 commit 80882b4
Show file tree
Hide file tree
Showing 50 changed files with 1,088 additions and 1,773 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
buildscript {
ext {
dokkaVersion = '0.9.18'
kotlin_version = '1.3.61'
kotlin_version = '1.5.20'
}
repositories {
google()
Expand Down
84 changes: 52 additions & 32 deletions desk360/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'org.jetbrains.dokka-android'

apply plugin: 'maven-publish'
def sdkArtifactId = 'desk360-android-sdk'
def sdkGroupId = 'com.github.Teknasyon-Teknoloji'
def sdkVersionName = "1.0.3"

android {
compileSdkVersion 28
compileSdkVersion 30

defaultConfig {
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 30
versionCode 6
versionName "1.0.2"
versionName sdkVersionName

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -53,56 +57,72 @@ android {
abortOnError false
}
}

buildFeatures {
dataBinding true
viewBinding true
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.multidex:multidex:2.0.1'
api 'androidx.constraintlayout:constraintlayout:2.1.0'
api 'androidx.multidex:multidex:2.0.1'

api 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
api 'androidx.lifecycle:lifecycle-extensions:2.2.0'

implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'

implementation 'androidx.legacy:legacy-support-v4:1.0.0'
api 'androidx.legacy:legacy-support-v4:1.0.0'
kapt 'androidx.lifecycle:lifecycle-compiler:2.2.0'

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

//navigation controller
implementation 'androidx.navigation:navigation-fragment-ktx:2.1.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.1.0'
api 'androidx.navigation:navigation-fragment-ktx:2.1.0'
api 'androidx.navigation:navigation-ui-ktx:2.1.0'

//http connection libs
implementation 'com.google.code.gson:gson:2.8.6'
implementation "com.squareup.retrofit2:retrofit:2.7.0"
implementation "com.squareup.retrofit2:converter-gson:2.7.0"
implementation "com.squareup.okhttp3:logging-interceptor:4.2.0"
implementation "com.squareup.retrofit2:converter-scalars:2.3.0"
api 'com.google.code.gson:gson:2.8.6'
api "com.squareup.retrofit2:retrofit:2.7.0"
api "com.squareup.retrofit2:converter-gson:2.7.0"
api "com.squareup.okhttp3:logging-interceptor:4.2.0"
api "com.squareup.retrofit2:converter-scalars:2.3.0"

//recyclerview
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api 'androidx.recyclerview:recyclerview:1.1.0'
api 'androidx.core:core-ktx:1.2.0'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

//
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.17'
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
api 'io.reactivex.rxjava2:rxjava:2.2.17'

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha05'
implementation 'com.karumi:dexter:6.0.0'
api 'androidx.appcompat:appcompat:1.1.0'
api 'com.google.android.material:material:1.2.0-alpha05'
api 'com.karumi:dexter:6.0.0'

implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'
}
repositories {
mavenCentral()
api 'com.github.bumptech.glide:glide:4.12.0'
kapt 'com.github.bumptech.glide:compiler:4.12.0'
}

task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier "sources"
}
archiveClassifier.set("sources")
}

project.afterEvaluate {
publishing {
publications {
library(MavenPublication) {
from components.release
groupId sdkGroupId
artifactId sdkArtifactId
version sdkVersionName
artifact(sourceJar)
}
}
}
}
11 changes: 5 additions & 6 deletions desk360/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">

<application>
<activity
android:name="com.teknasyon.desk360.view.activity.Desk360SplashActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateHidden|adjustResize" />

<activity
android:name="com.teknasyon.desk360.view.activity.Desk360BaseActivity"
android:label="@string/SUPPORT_TITLE"
android:screenOrientation="portrait"
android:launchMode="singleTop"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateHidden|adjustResize" />

</application>

</manifest>
33 changes: 0 additions & 33 deletions desk360/src/main/java/com/teknasyon/desk360/Desk360Application.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.json.JSONObject
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import java.util.*


abstract class BaseCallback<T> : Callback<T> {
Expand All @@ -32,9 +33,7 @@ abstract class BaseCallback<T> : Callback<T> {
val error =
JSONObject(JSONObject(jsonObject.getString("meta")).getString("error"))

val errorCode: String = error.getString("code")

when (errorCode) {
when (val errorCode: String = error.getString("code")) {
"expired_at" -> {
cloneRequest = call.clone()
val register = Desk360Register()
Expand All @@ -45,7 +44,6 @@ abstract class BaseCallback<T> : Callback<T> {
if (Desk360Constants.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
register.app_version = Desk360Constants.manager?.appVersion
register.language_code = Desk360Constants.manager?.languageCode
register.time_zone = Desk360Constants.manager?.timeZone

Desk360RetrofitFactory.instance.desk360Service.register(register)
.enqueue(object : Callback<Desk360RegisterResponse> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.teknasyon.desk360.connection

import com.teknasyon.desk360.BuildConfig
import com.teknasyon.desk360.helper.Desk360Constants
import com.teknasyon.desk360.helper.Environment
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
Expand All @@ -26,7 +27,7 @@ class Desk360RetrofitFactory private constructor() {
var request = chain.request()
request = request.newBuilder().apply {
addHeader("Version", BuildConfig.VERSION_NAME)
Desk360Constants.manager?.environment?.let { addHeader("Environment", it) }
addHeader("Environment", Environment.PRODUCTION)
}.build()
chain.proceed(request)
}
Expand All @@ -36,7 +37,7 @@ class Desk360RetrofitFactory private constructor() {
retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.baseUrl(Desk360Constants.baseURL!!)
.baseUrl(Desk360Constants.baseURL)
.build()

desk360Service = retrofit!!.create(Desk360Service::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ interface Desk360Service {
@GET("api/v1/tickets/{ticket_id}")
fun getMessages(
@Header("Authorization") token: String = "Bearer ${Desk360Config.instance.getDesk360Preferences()?.data?.access_token}",
@Path("ticket_id") ticket_id: Int
@Path("ticket_id") ticketId: Int
): Call<Desk360TicketMessage>

@POST("api/v1/tickets/{ticket_id}/messages")
fun addMessage(
@Header("Authorization") token: String = "Bearer ${Desk360Config.instance.getDesk360Preferences()?.data?.access_token}",
@Path("ticket_id") ticket_id: Int,
@Path("ticket_id") ticketId: Int,
@Query("message") message: String
): Call<Desk360MessageResponse>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AutoResizeTextView extends TextView {

// Interface for resize notifications
public interface OnTextResizeListener {
public void onTextResize(TextView textView, float oldSize, float newSize);
void onTextResize(TextView textView, float oldSize, float newSize);
}

// Our ellipse string
Expand Down
10 changes: 10 additions & 0 deletions desk360/src/main/java/com/teknasyon/desk360/helper/BindingExt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.teknasyon.desk360.helper

import android.app.Activity
import androidx.annotation.LayoutRes
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding

fun <T : ViewDataBinding> Activity.binding(
@LayoutRes resId: Int
): Lazy<T> = lazy { DataBindingUtil.setContentView(this, resId) }
27 changes: 11 additions & 16 deletions desk360/src/main/java/com/teknasyon/desk360/helper/Desk360Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@ import android.content.Intent
import com.teknasyon.desk360.view.activity.Desk360SplashActivity

class Desk360Client {
var token: String? = ""
var targetId: String? = ""
var deviceToken: String? = ""
var ticketId: String? = ""
var notificationToken: String? = ""
var deviceId: String? = ""

fun start(context: Context) {
context.startActivity(getIntent(context))
}

fun getIntent(context: Context): Intent {
val intent = Intent(context, Desk360SplashActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
return Intent(context, Desk360SplashActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

Desk360Constants.manager?.let { manager ->
manager.intentFlags?.forEach { flag ->
intent.addFlags(flag)
}

intent.putExtra(Desk360SplashActivity.EXTRA_APP_ID, context.applicationInfo.processName)
intent.putExtra(Desk360SplashActivity.EXTRA_TARGET_ID, targetId)
intent.putExtra(Desk360SplashActivity.EXTRA_TOKEN, token)
intent.putExtra(Desk360SplashActivity.EXTRA_DEVICE_TOKEN, deviceToken)
putExtra(Desk360SplashActivity.EXTRA_APP_ID, context.applicationInfo.processName)
putExtra(Desk360SplashActivity.EXTRA_TARGET_ID, ticketId)
putExtra(Desk360SplashActivity.EXTRA_TOKEN, notificationToken)
putExtra(Desk360SplashActivity.EXTRA_DEVICE_TOKEN, deviceId)
}

return intent
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.teknasyon.desk360.helper

import android.content.Context
import com.teknasyon.desk360.viewmodel.GetTypesViewModel

/**
* Created by seyfullah on 14,June,2019
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
package com.teknasyon.desk360.helper

import android.os.Build
import android.text.TextUtils
import com.teknasyon.desk360.model.Desk360Register
import com.teknasyon.desk360.modelv2.Desk360ConfigRequestModel
import java.util.*

object Desk360Helper {

fun createDesk360ConfigRequestModel() = Desk360ConfigRequestModel().apply {
language_code = Desk360Constants.manager?.languageCode.toString()
language_code_tag = Desk360Constants.manager?.languageTag
language_code_tag = getLanguageTag()
country_code = Desk360Constants.manager?.countryCode?.toUpperCase()
}

fun createDesk360RegisterRequestModel() = Desk360Register().apply {
app_key = Desk360Constants.manager?.appKey
device_id = Desk360Config.instance.getDesk360Preferences()?.adId
app_platform = if (Desk360Constants.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
app_platform =
if (Desk360Constants.manager?.platform == Platform.HUAWEI) "Huawei" else "Android"
app_version = Desk360Constants.manager?.appVersion
language_code = Desk360Constants.manager?.languageCode
time_zone = Desk360Constants.manager?.timeZone
}

private fun getLanguageTag() =
if (Desk360Constants.manager?.languageCode.isNullOrEmpty() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
Locale.getDefault().toLanguageTag().toLowerCase()
else
null

fun checkNotEmpty(value: String?, errorMessage: Any): String? {
return if (TextUtils.isEmpty(value)) {
throw IllegalArgumentException(errorMessage.toString())
} else {
value
}
}
}
Loading

0 comments on commit 80882b4

Please sign in to comment.