Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AzharRivaldi authored Mar 16, 2021
1 parent 0f64126 commit 5175280
Show file tree
Hide file tree
Showing 40 changed files with 1,068 additions and 0 deletions.
45 changes: 45 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.azhar.kbbi"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

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

implementation 'com.github.nakshay:texthighlighterapi:1.2.2'
implementation 'com.github.vipulasri:timelineview:1.1.5'
implementation 'com.amitshekhar.android:android-networking:1.0.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
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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.azhar.kbbi">

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

<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:usesCleartextTraffic="true"
tools:targetApi="q">
<activity
android:name=".activities.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>
100 changes: 100 additions & 0 deletions app/src/main/java/com/azhar/kbbi/activities/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.azhar.kbbi.activities

import android.app.ProgressDialog
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.androidnetworking.AndroidNetworking
import com.androidnetworking.common.Priority
import com.androidnetworking.error.ANError
import com.androidnetworking.interfaces.JSONObjectRequestListener
import com.azhar.kbbi.R
import com.azhar.kbbi.adapter.MainAdapter
import com.azhar.kbbi.model.ModelMain
import com.azhar.kbbi.networking.ApiEndpoint
import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONException
import org.json.JSONObject
import java.util.*

class MainActivity : AppCompatActivity() {

var mainAdapter: MainAdapter? = null
var modelMain: MutableList<ModelMain> = ArrayList()
var listArti: MutableList<ModelMain> = ArrayList()
var strInputTeks: String = ""
var progressDialog: ProgressDialog? = null

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

progressDialog = ProgressDialog(this)
progressDialog?.setTitle("Mohon Tunggu")
progressDialog?.setCancelable(false)
progressDialog?.setMessage("Sedang mencari data...")

linearHasil.setVisibility(View.GONE)
rvListTranslation.setLayoutManager(LinearLayoutManager(this))
rvListTranslation.setHasFixedSize(true)

btnTranslation.setOnClickListener {
strInputTeks = teksInput.getText().toString()
if (strInputTeks.isEmpty()) {
Toast.makeText(this@MainActivity, "Form tidak boleh kosong!", Toast.LENGTH_SHORT).show()
} else {
getDataBrand(strInputTeks)
}
}
}

private fun getDataBrand(strInputTeks: String) {
progressDialog?.show()
modelMain.clear()
AndroidNetworking.get(ApiEndpoint.BASEURL)
.addPathParameter("query", strInputTeks)
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONObject(object : JSONObjectRequestListener {
override fun onResponse(response: JSONObject) {
progressDialog?.dismiss()
try {
val jsonObject = response.getJSONObject("data")
val jsonArray = jsonObject.getJSONArray("resultLists")
for (i in 0 until jsonArray.length()) {
val jsonObjectKata = jsonArray.getJSONObject(i)

val dataModel = ModelMain()
dataModel.strKata = jsonObjectKata.getString("kata")

val jsonArrayArti = jsonObjectKata.getJSONArray("arti")
for (j in 0 until jsonArrayArti.length()) {
val artiKata = jsonArrayArti[j].toString()
dataModel.strArti = artiKata
listArti.add(dataModel)
}

modelMain.add(dataModel)
}
mainAdapter = MainAdapter(modelMain)
rvListTranslation.adapter = mainAdapter
mainAdapter?.notifyDataSetChanged()

linearHasil.visibility = View.VISIBLE
} catch (e: JSONException) {
Toast.makeText(this@MainActivity, "Oops, gagal menampilkan jenis dokumen.",
Toast.LENGTH_SHORT).show()
}
}

override fun onError(anError: ANError) {
progressDialog?.dismiss()
Toast.makeText(this@MainActivity, "Oops! Sepertinya ada masalah dengan koneksi internet kamu.",
Toast.LENGTH_SHORT).show()
}
})
}

}
67 changes: 67 additions & 0 deletions app/src/main/java/com/azhar/kbbi/adapter/MainAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.azhar.kbbi.adapter

import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.azhar.kbbi.R
import com.azhar.kbbi.model.ModelMain
import com.github.akshay_naik.texthighlighterapi.TextHighlighter
import com.github.vipulasri.timelineview.TimelineView

/**
* Created by Azhar Rivaldi on 11-03-2021
*/

class MainAdapter(private val modelMainList: List<ModelMain>) : RecyclerView.Adapter<MainAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item_main, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val data = modelMainList[position]
val highlighter = TextHighlighter()
highlighter.setColorForTheToken("a", "red")
highlighter.setColorForTheToken("cak", "red")
highlighter.setColorForTheToken("n", "red")
highlighter.setColorForTheToken("v", "red")
highlighter.setColorForTheToken("Huk", "red")
highlighter.setColorForTheToken("Prm", "red")
highlighter.setColorForTheToken("ki", "purple")
highlighter.setColorForTheToken("Ling", "red")
highlighter.setColorForTheToken("ark", "red")
highlighter.setColorForTheToken("Sas", "red")
highlighter.setColorForTheToken("Kim", "red")
highlighter.setColorForTheToken("Komp", "red")
highlighter.setColorForTheToken("sing", "red")
highlighter.setColorForTheToken("adv", "red")
highlighter.setColorForTheToken("num", "red")
highlighter.setColorForTheToken("Ek", "red")
highlighter.setColorForTheToken("kas", "red")
highlighter.setColorForTheToken("Fis", "red")
highlighter.setColorForTheToken("Mat", "red")
highlighter.setColorForTheToken("kp", "red")
val highlightedText = highlighter.getHighlightedText(data.strArti)
holder.tvKata.text = data.strKata
holder.tvArti.text = Html.fromHtml(highlightedText)
}

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

internal class ViewHolder(itemView: View, viewType: Int) : RecyclerView.ViewHolder(itemView) {
var timelineView: TimelineView
var tvKata: TextView
var tvArti: TextView

init {
timelineView = itemView.findViewById(R.id.timelineView)
tvKata = itemView.findViewById(R.id.tvKata)
tvArti = itemView.findViewById(R.id.tvArti)
}
}
}
10 changes: 10 additions & 0 deletions app/src/main/java/com/azhar/kbbi/model/ModelMain.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.azhar.kbbi.model

/**
* Created by Azhar Rivaldi on 11-03-2021
*/

class ModelMain {
var strKata: String? = null
var strArti: String? = null
}
9 changes: 9 additions & 0 deletions app/src/main/java/com/azhar/kbbi/networking/ApiEndpoint.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.azhar.kbbi.networking

/**
* Created by Azhar Rivaldi on 24-02-2021
*/

object ApiEndpoint {
var BASEURL = "https://kbbi-api-amm.herokuapp.com/search?q={query}"
}
30 changes: 30 additions & 0 deletions app/src/main/res/drawable-v24/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeWidth="1"
android:strokeColor="#00000000" />
</vector>
18 changes: 18 additions & 0 deletions app/src/main/res/drawable/bg_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_pressed="true">
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
<corners android:radius="50dp" />
</shape>
</item>

<item>
<shape android:shape="rectangle">
<gradient android:endColor="@color/colorPrimaryDark"
android:startColor="@color/colorPrimaryDark" />
<corners android:radius="50dp" />
</shape>
</item>
</selector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/bg_circle.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/colorPrimaryDark" />
</shape>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/bg_rounded_line.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="@color/colorPrimaryDark" />
</shape>
7 changes: 7 additions & 0 deletions app/src/main/res/drawable/bg_rounded_rect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark" />
<corners
android:bottomRightRadius="50dp" />
</shape>
Binary file added app/src/main/res/drawable/ic_kamus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 5175280

Please sign in to comment.