Skip to content

Instantly share code, notes, and snippets.

View DjakaTechnology's full-sized avatar
🏠

Djaka Pradana Jaya Priambudi DjakaTechnology

🏠
View GitHub Profile
class VPMainAdapter : RecyclerView.Adapter<VPMainAdapter.MyViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getItemCount(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
class VPMainAdapter(var data:ArrayList<PageModel>) : RecyclerView.Adapter<VPMainAdapter.MyViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.vp_item, parent,false))
}
override fun getItemCount(): Int {
return data.size
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
class MainActivity : AppCompatActivity() {
val data: ArrayList<PageModel> = ArrayList()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
prepareData()
prepareViewPager()
}
try{
$device = new DeviceKey();
$device->user_id = $user->id;
$device->device_key = request('device_key');
$device->save();
}catch(QueryException $e){}
private fun getRetrofit(c: Context): Retrofit {
val pref = c.getSharedPreferences(SharedKey.Session.SESSION, MODE_PRIVATE)
val client = OkHttpClient.Builder().addInterceptor { chain ->
val newRequest = chain.request().newBuilder()
.addHeader("Authorization", "Bearer " + pref.getString(SharedKey.Session.TOKEN, "")!!)
.build()
chain.proceed(newRequest)
}.build()
return Retrofit.Builder().baseUrl(baseUrl).client(client).addConverterFactory(
object Request{
suspend fun login(context:Context, email:String, password:String, token:String):UserModel?{
val api = getApiService(context)
val request = api.login(email, password, token)
return try{
return request.await().body()!!
}catch (e: Exception){
Log.e("TAG", "Login Failed" + e.message)
null
}
private fun doUpload(fileToUpload: MultipartBody.Part) {
uploadJob = CoroutineScope(Dispatchers.IO).launch {
val result = Request.uploadImg(baseContext, fileToUpload)
withContext(Dispatchers.Main) {
if (result.result == true) onSucceed(result)
}
}
}
if (data[i].value != null) {
Glide.with(c).load(data[i].value).apply(
RequestOptions()
.placeholder(R.drawable.loading)
.fitCenter()
).into(myViewHolder.itemView.img_thumbnail)
myViewHolder.itemView.img_thumbnail.setOnClickListener {
var i = Intent(c, ImageActivity::class.java)
i.putExtra(SharedKey.App.ID, data[myViewHolder.adapterPosition].value)
fun getUserModel(c: Context): UserModel? {
val pref = c.getSharedPreferences(Session.SESSION, MODE_PRIVATE)
return try {
Gson().fromJson<UserModel>(pref.getString(Session.USER, null), UserModel::class.java)
} catch (e: Exception) { null }
}
v.img_icon.run {
when(data[i].permissionTypeId){
1 -> setImageDrawable(ContextCompat.getDrawable(c, R.drawable.ic_plus))
2 -> setImageDrawable(ContextCompat.getDrawable(c, R.drawable.ic_permission_green))
3 -> setImageDrawable(ContextCompat.getDrawable(c, R.drawable.ic_clock_orange))
}
}
v.tv_status.run{
when(data[i].statusId){