Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated to AndroidX and Java 8 #338

Merged
merged 1 commit into from
Feb 11, 2021
Merged
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
21 changes: 11 additions & 10 deletions chatkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
compileSdkVersion 29
buildToolsVersion '29.0.2'

defaultConfig {
minSdkVersion 14
Expand All @@ -16,6 +16,11 @@ android {
abortOnError false
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

publish {
Expand All @@ -28,15 +33,11 @@ publish {
website = 'https://github.com/stfalcon-studio/ChatKit.git'
}

ext {
supportVersion = '27.1.1'
flexboxVersion = '1.0.0'
}

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

implementation "com.android.support:appcompat-v7:$supportVersion"
implementation "com.android.support:design:$supportVersion"
implementation "com.google.android:flexbox:$flexboxVersion"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation "com.google.android:flexbox:1.0.0"
implementation 'androidx.recyclerview:recyclerview:1.1.0'
}
3 changes: 1 addition & 2 deletions chatkit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.stfalcon.chatkit">
<manifest package="com.stfalcon.chatkit">

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package com.stfalcon.chatkit.commons;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import androidx.annotation.Nullable;

/**
* Callback for implementing images loading in message list
*/
Expand Down
11 changes: 6 additions & 5 deletions chatkit/src/main/java/com/stfalcon/chatkit/commons/Style.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.support.annotation.AttrRes;
import android.support.annotation.ColorRes;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;

import androidx.annotation.AttrRes;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import androidx.core.content.ContextCompat;

import com.stfalcon.chatkit.R;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

package com.stfalcon.chatkit.commons;

import android.support.v7.widget.RecyclerView;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

/**
* Base ViewHolder
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public interface IUser {
* Returns the user's id
*
* @return the user's id
* */
*/
String getId();

/**
* Returns the user's name
*
* @return the user's name
* */
*/
String getName();

/**
* Returns the user's avatar image url
*
* @return the user's avatar image url
* */
*/
String getAvatar();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package com.stfalcon.chatkit.commons.models;

import android.support.annotation.Nullable;
import androidx.annotation.Nullable;

import com.stfalcon.chatkit.messages.MessageHolders;

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package com.stfalcon.chatkit.dialogs;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.util.AttributeSet;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.SimpleItemAnimator;

import com.stfalcon.chatkit.commons.models.IDialog;

/**
Expand Down Expand Up @@ -73,7 +74,7 @@ public void setAdapter(Adapter adapter) {
* @param adapter Adapter. Must extend DialogsListAdapter
* @param <DIALOG> Dialog model class
*/
public <DIALOG extends IDialog>
public <DIALOG extends IDialog<?>>
void setAdapter(DialogsListAdapter<DIALOG> adapter) {
setAdapter(adapter, false);
}
Expand All @@ -85,7 +86,7 @@ void setAdapter(DialogsListAdapter<DIALOG> adapter) {
* @param reverseLayout weather to use reverse layout for layout manager.
* @param <DIALOG> Dialog model class
*/
public <DIALOG extends IDialog>
public <DIALOG extends IDialog<?>>
void setAdapter(DialogsListAdapter<DIALOG> adapter, boolean reverseLayout) {
SimpleItemAnimator itemAnimator = new DefaultItemAnimator();
itemAnimator.setSupportsChangeAnimations(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@

import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.stfalcon.chatkit.R;
import com.stfalcon.chatkit.commons.ImageLoader;
import com.stfalcon.chatkit.commons.ViewHolder;
Expand Down Expand Up @@ -216,8 +217,9 @@ public void addItem(int position, DIALOG dialog) {

/**
* Move an item
*
* @param fromPosition the actual position of the item
* @param toPosition the new position of the item
* @param toPosition the new position of the item
*/
public void moveItem(int fromPosition, int toPosition) {
DIALOG dialog = items.remove(fromPosition);
Expand Down Expand Up @@ -327,15 +329,12 @@ public boolean updateDialogWithMessage(String dialogId, IMessage message) {
* Sort dialog by last message date
*/
public void sortByLastMessageDate() {
Collections.sort(items, new Comparator<DIALOG>() {
@Override
public int compare(DIALOG o1, DIALOG o2) {
if (o1.getLastMessage().getCreatedAt().after(o2.getLastMessage().getCreatedAt())) {
return -1;
} else if (o1.getLastMessage().getCreatedAt().before(o2.getLastMessage().getCreatedAt())) {
return 1;
} else return 0;
}
Collections.sort(items, (o1, o2) -> {
if (o1.getLastMessage().getCreatedAt().after(o2.getLastMessage().getCreatedAt())) {
return -1;
} else if (o1.getLastMessage().getCreatedAt().before(o2.getLastMessage().getCreatedAt())) {
return 1;
} else return 0;
});
notifyDataSetChanged();
}
Expand Down Expand Up @@ -443,15 +442,15 @@ void setStyle(DialogListStyle dialogStyle) {
}

/**
* @return the position of a dialog in the dialogs list.
*/
* @return the position of a dialog in the dialogs list.
*/
public int getDialogPosition(DIALOG dialog) {
return this.items.indexOf(dialog);
}

/*
* LISTENERS
* */
* LISTENERS
* */
public interface OnDialogClickListener<DIALOG extends IDialog> {
void onDialogClick(DIALOG dialog);
}
Expand All @@ -469,8 +468,8 @@ public interface OnDialogViewLongClickListener<DIALOG extends IDialog> {
}

/*
* HOLDERS
* */
* HOLDERS
* */
public abstract static class BaseDialogViewHolder<DIALOG extends IDialog>
extends ViewHolder<DIALOG> {

Expand Down Expand Up @@ -525,15 +524,15 @@ public static class DialogViewHolder<DIALOG extends IDialog> extends BaseDialogV

public DialogViewHolder(View itemView) {
super(itemView);
root = (ViewGroup) itemView.findViewById(R.id.dialogRootLayout);
container = (ViewGroup) itemView.findViewById(R.id.dialogContainer);
tvName = (TextView) itemView.findViewById(R.id.dialogName);
tvDate = (TextView) itemView.findViewById(R.id.dialogDate);
tvLastMessage = (TextView) itemView.findViewById(R.id.dialogLastMessage);
tvBubble = (TextView) itemView.findViewById(R.id.dialogUnreadBubble);
ivLastMessageUser = (ImageView) itemView.findViewById(R.id.dialogLastMessageUserAvatar);
ivAvatar = (ImageView) itemView.findViewById(R.id.dialogAvatar);
dividerContainer = (ViewGroup) itemView.findViewById(R.id.dialogDividerContainer);
root = itemView.findViewById(R.id.dialogRootLayout);
container = itemView.findViewById(R.id.dialogContainer);
tvName = itemView.findViewById(R.id.dialogName);
tvDate = itemView.findViewById(R.id.dialogDate);
tvLastMessage = itemView.findViewById(R.id.dialogLastMessage);
tvBubble = itemView.findViewById(R.id.dialogUnreadBubble);
ivLastMessageUser = itemView.findViewById(R.id.dialogLastMessageUserAvatar);
ivAvatar = itemView.findViewById(R.id.dialogAvatar);
dividerContainer = itemView.findViewById(R.id.dialogDividerContainer);
divider = itemView.findViewById(R.id.dialogDivider);

}
Expand Down Expand Up @@ -680,30 +679,24 @@ public void onBind(final DIALOG dialog) {
tvBubble.setVisibility(dialogStyle.isDialogUnreadBubbleEnabled() &&
dialog.getUnreadCount() > 0 ? VISIBLE : GONE);

container.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (onDialogClickListener != null) {
onDialogClickListener.onDialogClick(dialog);
}
if (onDialogViewClickListener != null) {
onDialogViewClickListener.onDialogViewClick(view, dialog);
}
container.setOnClickListener(view -> {
if (onDialogClickListener != null) {
onDialogClickListener.onDialogClick(dialog);
}
if (onDialogViewClickListener != null) {
onDialogViewClickListener.onDialogViewClick(view, dialog);
}
});


container.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
if (onLongItemClickListener != null) {
onLongItemClickListener.onDialogLongClick(dialog);
}
if (onDialogViewLongClickListener != null) {
onDialogViewLongClickListener.onDialogViewLongClick(view, dialog);
}
return onLongItemClickListener != null || onDialogViewLongClickListener != null;
container.setOnLongClickListener(view -> {
if (onLongItemClickListener != null) {
onLongItemClickListener.onDialogLongClick(dialog);
}
if (onDialogViewLongClickListener != null) {
onDialogViewLongClickListener.onDialogViewLongClick(view, dialog);
}
return onLongItemClickListener != null || onDialogViewLongClickListener != null;
});
}

Expand Down
Loading