Skip to content

Commit c346b01

Browse files
committed
Migrated in kotin
1 parent f484cae commit c346b01

File tree

10 files changed

+297
-360
lines changed

10 files changed

+297
-360
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
apply plugin: 'com.android.application'
17+
apply plugin: 'kotlin-android'
1718

1819
android {
1920
compileSdkVersion 30
@@ -34,9 +35,8 @@ android {
3435
}
3536

3637
dependencies {
37-
implementation fileTree(dir: 'libs', include: ['*.jar'])
38+
//implementation fileTree(dir: 'libs', include: ['*.jar'])
3839

39-
//implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4040
implementation 'androidx.appcompat:appcompat:1.3.0'
4141
implementation 'com.google.android.material:material:1.3.0'
4242
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
~ See the License for the specific language governing permissions and
1414
~ limitations under the License.
1515
-->
16-
1716
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1817
package="com.devs.readmoreoptiondemo">
1918

@@ -24,8 +23,9 @@
2423
android:roundIcon="@mipmap/ic_launcher_round"
2524
android:supportsRtl="true"
2625
android:theme="@style/AppTheme">
27-
<activity android:name=".MainActivity"
28-
android:screenOrientation="portrait">
26+
<activity
27+
android:label="@string/app_name"
28+
android:name="com.devs.readmoreoptiondemo.MainActivity">
2929
<intent-filter>
3030
<action android:name="android.intent.action.MAIN" />
3131

app/src/main/java/com/devs/readmoreoptiondemo/MainActivity.java renamed to app/src/main/java/com/devs/readmoreoptiondemo/MainActivity.kt

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,30 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
16-
package com.devs.readmoreoptiondemo;
17-
18-
import android.graphics.Color;
19-
import android.media.TimedText;
20-
import android.os.Bundle;
21-
import android.widget.TextView;
22-
23-
import androidx.appcompat.app.AppCompatActivity;
24-
import androidx.recyclerview.widget.DividerItemDecoration;
25-
import androidx.recyclerview.widget.LinearLayoutManager;
26-
import androidx.recyclerview.widget.RecyclerView;
27-
28-
import com.devs.readmoreoption.ReadMoreOption;
29-
30-
31-
public class MainActivity extends AppCompatActivity {
32-
33-
@Override
34-
protected void onCreate(Bundle savedInstanceState) {
35-
super.onCreate(savedInstanceState);
36-
setContentView(R.layout.activity_main);
37-
38-
39-
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.my_recycler_view);
40-
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
41-
recyclerView.setLayoutManager(mLayoutManager);
42-
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
43-
mLayoutManager.getOrientation());
44-
recyclerView.addItemDecoration(dividerItemDecoration);
45-
MyAdapter mAdapter = new MyAdapter(this);
46-
recyclerView.setAdapter(mAdapter);
15+
package com.devs.readmoreoptiondemo
16+
17+
import android.os.Bundle
18+
import android.view.View
19+
import androidx.appcompat.app.AppCompatActivity
20+
import androidx.recyclerview.widget.DividerItemDecoration
21+
import androidx.recyclerview.widget.LinearLayoutManager
22+
import androidx.recyclerview.widget.RecyclerView
23+
24+
class MainActivity : AppCompatActivity() {
25+
26+
override fun onCreate(savedInstanceState: Bundle?) {
27+
super.onCreate(savedInstanceState)
28+
setContentView(R.layout.activity_main)
29+
val recyclerView = findViewById<View>(R.id.my_recycler_view) as RecyclerView
30+
val mLayoutManager = LinearLayoutManager(this)
31+
recyclerView.layoutManager = mLayoutManager
32+
val dividerItemDecoration = DividerItemDecoration(
33+
recyclerView.context,
34+
mLayoutManager.orientation
35+
)
36+
recyclerView.addItemDecoration(dividerItemDecoration)
37+
val mAdapter = MyAdapter(this)
38+
recyclerView.adapter = mAdapter
4739

4840

4941
// TextView tv = (TextView)findViewById(R.id.tv);
@@ -61,6 +53,5 @@ protected void onCreate(Bundle savedInstanceState) {
6153
// .expandAnimation(true)
6254
// .build();
6355
// readMoreOption.addReadMoreTo(tv, getString(R.string.dummy_text));
64-
6556
}
66-
}
57+
}

app/src/main/java/com/devs/readmoreoptiondemo/MyAdapter.java

Lines changed: 0 additions & 78 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright (c) 2018 Deven.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package com.devs.readmoreoptiondemo
16+
17+
import android.content.Context
18+
import android.text.Html
19+
import android.view.LayoutInflater
20+
import android.view.View
21+
import android.view.ViewGroup
22+
import android.widget.TextView
23+
import androidx.recyclerview.widget.RecyclerView
24+
import com.devs.readmoreoption.ReadMoreOption
25+
26+
/**
27+
* Created by ${Deven} on 6/2/18.
28+
*/
29+
internal class MyAdapter internal constructor(private val context: Context) :
30+
RecyclerView.Adapter<MyAdapter.ViewHolder>() {
31+
32+
private val readMoreOption: ReadMoreOption
33+
34+
// Provide a reference to the views for each data item
35+
// Complex data items may need more than one view per item, and
36+
// you provide access to all the views for a data item in a view holder
37+
internal class ViewHolder(v: View) : RecyclerView.ViewHolder(v) {
38+
// each data item is just a string in this case
39+
var mTextView: TextView
40+
41+
init {
42+
mTextView = v.findViewById(R.id.tv)
43+
}
44+
}
45+
46+
// Create new views (invoked by the layout manager)
47+
override fun onCreateViewHolder(
48+
parent: ViewGroup,
49+
viewType: Int
50+
): ViewHolder {
51+
// create a new view
52+
val v = LayoutInflater.from(parent.context)
53+
.inflate(R.layout.item_view, parent, false) as View
54+
return ViewHolder(v)
55+
}
56+
57+
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
58+
if (position % 2 == 0) {
59+
readMoreOption.addReadMoreTo(
60+
holder.mTextView,
61+
Html.fromHtml(context.getString(R.string.dummy_text))
62+
)
63+
} else {
64+
readMoreOption.addReadMoreTo(
65+
holder.mTextView,
66+
Html.fromHtml(context.getString(R.string.dummy_text)).toString()
67+
)
68+
}
69+
}
70+
71+
// Return the size of your dataset (invoked by the layout manager)
72+
override fun getItemCount(): Int {
73+
return 20
74+
}
75+
76+
init {
77+
readMoreOption = ReadMoreOption.Builder(context)
78+
.build()
79+
}
80+
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
// Top-level build file where you can add configuration options common to all sub-projects/modules.
1717

1818
buildscript {
19-
19+
ext.kotlin_version = "1.4.31"
2020
repositories {
2121
google()
2222
jcenter()
2323
}
2424
dependencies {
2525
classpath 'com.android.tools.build:gradle:4.2.1'
26-
26+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2727

2828
// NOTE: Do not place your application dependencies here; they belong
2929
// in the individual module build.gradle files

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ org.gradle.jvmargs=-Xmx1536m
2727
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
2828
# org.gradle.parallel=true
2929

30-
android.useAndroidX = true
30+
android.useAndroidX=true
3131
android.enableJetifier=true

readmoreoption/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
apply plugin: 'com.android.library'
17+
apply plugin: 'kotlin-android'
1718

1819
android {
1920
compileSdkVersion 30
@@ -24,7 +25,7 @@ android {
2425
minSdkVersion 16
2526
targetSdkVersion 30
2627
versionCode 1
27-
versionName "1.0.1"
28+
versionName "1.0.2"
2829

2930
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
3031

@@ -41,9 +42,4 @@ android {
4142

4243
dependencies {
4344
implementation fileTree(dir: 'libs', include: ['*.jar'])
44-
// implementation 'androidx.appcompat:appcompat:1.3.0'
45-
// implementation 'com.android.support:appcompat-v7:27.1.1'
46-
// testImplementation 'junit:junit:4.12'
47-
// androidTestImplementation 'com.android.support.test:runner:1.0.2'
48-
// androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
4945
}

0 commit comments

Comments
 (0)