Skip to content

Commit

Permalink
Implement module feature abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
wisnukurniawan committed Jan 24, 2020
0 parents commit 3096f22
Show file tree
Hide file tree
Showing 125 changed files with 1,791 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.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
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
37 changes: 37 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply from: "$rootDir/build-system/dependencies-feature-generator.gradle"

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.wisnu.ordertiket"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
project.config.each { module ->
project.dependencies.add("implementation", project(":${module}"))
}

implementation project(':launcher:main')

implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation "androidx.cardview:cardview:1.0.0"
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.recyclerview:recyclerview:1.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
22 changes: 22 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.wisnu.ordertiket">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name=".MainApplication">
<activity android:name=".MainActivity">
<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/wisnu/ordertiket/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.wisnu.ordertiket

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import com.wisnu.launcher.main.Launcher
import com.wisnu.ordertiket.recyclerview.FeatureAdapter
import com.wisnu.ordertiket.recyclerview.FeatureUiModel
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val features = (applicationContext as? Launcher.Provider)?.launcher?.features
val featureUiModels = features?.map { FeatureUiModel(it.type, getString(it.title()), it.icon(), it.intent()) } ?: listOf()
val adapter = FeatureAdapter(featureUiModels) {
startActivity(it)
}
val layoutManager = GridLayoutManager(this, 3)
rv_feature.layoutManager = layoutManager
rv_feature.adapter = adapter
rv_feature.setHasFixedSize(true)
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/wisnu/ordertiket/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.wisnu.ordertiket

import android.app.Application
import com.wisnu.launcher.main.Launcher

class MainApplication : Application(), Launcher.Provider {
override lateinit var launcher: Launcher

override fun onCreate() {
super.onCreate()
launcher = MainLauncher(this)
launcher.onCreate()
}
}
19 changes: 19 additions & 0 deletions app/src/main/java/com/wisnu/ordertiket/MainLauncher.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wisnu.ordertiket

import android.app.Application
import com.wisnu.feature.order.flight.OrderFlightFeatureApplication
import com.wisnu.feature.order.hotel.OrderHotelFeatureApplication
import com.wisnu.feature.order.train.OrderTrainFeatureApplication
import com.wisnu.feature.setting.SettingFeatureApplication
import com.wisnu.feature.transaction.TransactionFeatureApplication
import com.wisnu.launcher.main.BaseLauncher

class MainLauncher(application: Application) : BaseLauncher(application) {
init {
registerFeatureApplication(OrderFlightFeatureApplication())
registerFeatureApplication(OrderHotelFeatureApplication())
registerFeatureApplication(OrderTrainFeatureApplication())
registerFeatureApplication(TransactionFeatureApplication())
registerFeatureApplication(SettingFeatureApplication())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.wisnu.ordertiket.recyclerview

import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.wisnu.ordertiket.R

class FeatureAdapter(
private val items: List<FeatureUiModel>,
private val onClick: (Intent) -> Unit
) : RecyclerView.Adapter<FeatureViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeatureViewHolder {
val itemView = LayoutInflater.from(parent.context).inflate(R.layout.view_feature_item, parent, false)
return FeatureViewHolder(itemView, onClick)
}

override fun getItemCount(): Int {
return items.size
}

override fun onBindViewHolder(holder: FeatureViewHolder, position: Int) {
holder.bindData(items[position])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.wisnu.ordertiket.recyclerview

import android.content.Intent

data class FeatureUiModel(
val type: Int,
val title: String,
val icon: Int,
val intent: Intent?
)
Loading

0 comments on commit 3096f22

Please sign in to comment.