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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
94 changes: 94 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
}

def koin_version = "2.1.6"
def lifecycleVersion = "2.2.0"
def retrofitVersion = '2.9.0'
def okhttpVersion = '4.9.0'
def glideVersion = '4.11.0'


android {
compileSdkVersion 30
buildToolsVersion "30.0.1"

defaultConfig {
applicationId "com.dhiwise.androidarch"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

flavorDimensions "default"
productFlavors {
development {
dimension "default"
applicationId "com.dhiwise.app.development"
resValue "string", "app_name", "kotlin-development"
buildConfigField "long", "test", "1212121"
buildConfigField "long", "test_4", "1313"
buildConfigField "String", "test_7","\"hwuewueyw\""
buildConfigField "boolean", "test_8", "false"
}
}


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

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
implementation "androidx.activity:activity-ktx:1.2.2"
implementation "androidx.fragment:fragment-ktx:1.3.2"

implementation 'com.google.android.material:material:1.3.0'

implementation "org.koin:koin-core:$koin_version"
implementation "org.koin:koin-core-ext:$koin_version"
implementation "org.koin:koin-androidx-scope:$koin_version"
implementation "org.koin:koin-androidx-viewmodel:$koin_version"


implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttpVersion"
implementation "com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation "com.github.bumptech.glide:glide:$glideVersion"


testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

implementation 'com.vmadalin:easypermissions-ktx:0.1.0'
}
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.dhiwise.app

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.dhiwise.app", appContext.packageName)
}
}
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest package="com.dhiwise.app" xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:largeHeap="true"
android:name="com.dhiwise.app.appcomponents.di.MyApp"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:theme="@style/Theme.MyApp">
<activity
android:name="com.dhiwise.app.modules.loginlight.ui.LoginLightActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name="com.dhiwise.app.modules.socialchatlight.ui.SocialChatLightActivity" android:screenOrientation="portrait"/>
<activity
android:name="com.dhiwise.app.modules.socialhomelight.ui.SocialHomeLightActivity" android:screenOrientation="portrait"/>
<activity
android:name="com.dhiwise.app.modules.socialcommentslight.ui.SocialCommentsLightActivity" android:screenOrientation="portrait"/>
</application>
</manifest>
16 changes: 16 additions & 0 deletions app/src/main/java/com/dhiwise/app/appcomponents/di/MyApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.dhiwise.app.appcomponents.di

import android.app.Application
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

class MyApp : Application() {

override fun onCreate() {
super.onCreate()

startKoin {
androidContext(this@MyApp)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.dhiwise.app.appcomponents.network

object ResponseCode {
const val OK = 200
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dhiwise.app.appcomponents.network

import com.dhiwise.app.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class RetrofitProvider {

private fun provideOkHttpClient(): OkHttpClient {
val builder = OkHttpClient().newBuilder()
.connectTimeout(5, TimeUnit.MINUTES)
.callTimeout(5, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.writeTimeout(1, TimeUnit.MINUTES)
if (BuildConfig.DEBUG) {
builder.addInterceptor(HttpLoggingInterceptor().apply {
this.level = HttpLoggingInterceptor.Level.BODY
})
}
return builder.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.dhiwise.app.appcomponents.ui

import android.graphics.drawable.Drawable
import android.view.View
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.dhiwise.app.R

@BindingAdapter(value = ["viewVisibility", "isInvisible"], requireAll = false)
fun setVisibility(view: View, isVisible: Boolean, isInvisible: Boolean) {
view.visibility =
if (isVisible) View.VISIBLE else if (isInvisible) View.INVISIBLE else View.GONE
}

@BindingAdapter(
value = ["imageUrl", "placeHolder", "placeHolderError", "cornerRadius"], requireAll = false
)
fun loadImageFromNetwork(
imageView: ImageView, url: String?, placeHolder: Drawable?,
placeHolderError: Drawable?,
cornerRadius: Float
) {
var imageURL = url

if (imageURL != null && !imageURL.isEmpty() && !imageURL.equals(
"",
ignoreCase = true
)
) {
imageURL = imageURL.trim { it <= ' ' }
if (imageURL.startsWith("/"))
imageURL = "" + url

val options = RequestOptions()
.placeholder(placeHolder)
.error(placeHolderError)
if (cornerRadius > 0)
options.transform(RoundedCorners(cornerRadius.toInt()))

Glide.with(imageView).load(imageURL).apply(options).into(imageView)
} else {
imageView.setImageDrawable(placeHolder)
}
}


@BindingAdapter(
value = ["imageRes", "cornerRadius", "circular"], requireAll = false
)
fun loadImageFromResource(
imageView: ImageView, imageRes: Drawable?, cornerRadius: Float, circular: Boolean
) {
if (imageRes == null) {
imageView.setImageResource(R.drawable.image_not_found)
} else {
val options = RequestOptions()
if (circular)
options.circleCrop()
if (cornerRadius > 0)
options.transform(RoundedCorners(cornerRadius.toInt()))
Glide.with(imageView).load(imageRes).apply(options).into(imageView)
}
}

@BindingAdapter(value = ["itemSpace"], requireAll = true)
fun addSpaceBetweenRecyclerItem(
recyclerView: RecyclerView,
itemSpace: Double,
) {
recyclerView.addItemDecoration(
RecyclerItemDecoration(itemSpace.toInt())
)
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.dhiwise.app.appcomponents.ui

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView


class RecyclerItemDecoration(spacing: Int) : RecyclerView.ItemDecoration() {
private var spacing = 0
private var displayMode = -1

val HORIZONTAL = 0
val VERTICAL = 1
val GRID = 2

init {
this.spacing = spacing
}

override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
val position = parent.getChildViewHolder(view).adapterPosition
val itemCount = state.itemCount
val layoutManager = parent.layoutManager
setSpacingForDirection(outRect, layoutManager, position, itemCount)
}


private fun setSpacingForDirection(
outRect: Rect,
layoutManager: RecyclerView.LayoutManager?,
position: Int,
itemCount: Int
) {

// Resolve display mode automatically
if (displayMode == -1) {
displayMode = resolveDisplayMode(layoutManager)
}
when (displayMode) {
HORIZONTAL -> {
outRect.left = spacing
outRect.right = if (position == itemCount - 1) spacing else 0
outRect.top = spacing
outRect.bottom = spacing
}
VERTICAL -> {
outRect.left = spacing
outRect.right = spacing
outRect.top = spacing
outRect.bottom = if (position == itemCount - 1) spacing else 0
}
GRID -> if (layoutManager is GridLayoutManager) {
val cols = layoutManager.spanCount
val rows = itemCount / cols
outRect.left = spacing
outRect.right = if (position % cols == cols - 1) spacing else 0
outRect.top = spacing
outRect.bottom = if (position / cols == rows - 1) spacing else 0
}
}
}

private fun resolveDisplayMode(layoutManager: RecyclerView.LayoutManager?): Int {
if (layoutManager is GridLayoutManager) return GRID
return if (layoutManager!!.canScrollHorizontally()) HORIZONTAL else VERTICAL
}
}
Loading