Skip to content

Instantly share code, notes, and snippets.

View hosseiniSeyRo's full-sized avatar

R.Hosseini hosseiniSeyRo

  • tehran
View GitHub Profile
@hosseiniSeyRo
hosseiniSeyRo / paginationInRecyclerView.txt
Last active November 8, 2019 06:50
pagination in recyclerView
private boolean isLoading = false;
private boolean isEndOfList = false;
private String currentPage = "1";
.
.
.
@Override
protected void onCreate(Bundle savedInstanceState) {
.
/* configure Search */
private void configureSearch() {
// add text change listener for searchView
searchView.addTextChangedListener(searchTextWatcher);
// set search Suggestion Adapter
searchSuggestionAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line);
searchView.setAdapter(searchSuggestionAdapter);
searchView.setThreshold(2);
public class ResponseWrapper<T> {
@NonNull
private Status status;
@Nullable
private T data;
@Nullable
private Integer errorCode;
@hosseiniSeyRo
hosseiniSeyRo / CustomeRecyclerViewAdapter
Last active October 1, 2019 13:25
Endless recyclerView+progressBar
public class CustomeRecyclerViewAdapter extends RecyclerView.Adapter<CustomeRecyclerViewAdapter.CustomViewHolder> {
private Context mContext;
private List<T> dataList = new ArrayList<>();
private OnItemClickedListener onItemClickedListener;
// for load more
private final int VIEW_TYPE_ITEM = 0;
private final int VIEW_TYPE_LOADING = 1;
private OnLoadMoreListener onLoadMoreListener;
@hosseiniSeyRo
hosseiniSeyRo / BaseAdapter.kt
Last active August 19, 2021 05:14
DataBinding BaseAdapter for RecyclerView by Kotlin
abstract class BaseAdapter<T>(private val itemClickListener: OnItemClickListener<T>) :
RecyclerView.Adapter<BaseAdapter<T>.MyViewHolder>() {
interface OnItemClickListener<T> {
fun onItemClick(item: T)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val binding = DataBindingUtil.inflate<ViewDataBinding>(
LayoutInflater.from(parent.context),
@hosseiniSeyRo
hosseiniSeyRo / SharePrefUtils.java
Last active December 7, 2019 14:01
SharePrefUtils
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;
public class SharePrefUtils {
//list of your keys here
public static final String IS_FIRST_LAUNCH = "is first launch";
@hosseiniSeyRo
hosseiniSeyRo / BaseActivity.kt
Created April 18, 2020 08:37
RtL Direction to whole app
open class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val configuration: Configuration = resources.configuration
configuration.setLayoutDirection(Locale("fa"))
resources.updateConfiguration(configuration, resources.displayMetrics)
}
}
<application
...
android:theme="@style/AppTheme">
<activity
android:name=".ui.main.MainActivity"
android:label="@string/app_name" />
<activity
android:name=".ui.main.SplashScreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/FullscreenTheme">
@hosseiniSeyRo
hosseiniSeyRo / circle.xml
Last active April 18, 2020 10:46
drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@color/numbersCircleBG" />
<size
android:width="120dp"
android:height="120dp" />
</shape>
fun convertImageToBase64(imageFile: File): String {
return ByteArrayOutputStream().use { outputStream ->
Base64OutputStream(outputStream, Base64.DEFAULT).use { base64FilterStream ->
imageFile.inputStream().use { inputStream ->
inputStream.copyTo(base64FilterStream)
}
}
return@use outputStream.toString()
}
}