Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
FOCUS

Mohamed Alouane alouanemed

:octocat:
FOCUS
View GitHub Profile
@alouanemed
alouanemed / viewModel.swift
Created Sep 6, 2020
retreive post fav reactions with rxswift
View viewModel.swift
let userInfo = reloadTrigger
.flatMapLatest { [apiService, selectedUser] in
apiService.fetchUserInfo(with: selectedUser.id)
.trackActivity(activityIndicator)
}
.share(replay: 1)
let favorites = userInfo
.flatMapLatest { [apiService] in
apiService.fetchFavorites(with: $0.id)
.trackActivity(activityIndicator)
View viewMode.swift
let onUnit = BehaviorRelay(value: "")
let onTotal = BehaviorRelay(value: "")
let onPriceUpdated = BehaviorRelay<ProductPriceEntity?>(value: nil)
let onQuantity = BehaviorRelay(value: 1)
var prices: [ProductPriceEntity] = []
Observable.combineLatest(onUnit, onQuantity).flatMapLatest{[weak self] (unit, qty) -> Observable<Void> in
guard let self = self else { return Observable.just(()) }
let price = self.unitPrices.value[unit]?.filter { price in
View collectionview.swift
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
private let reuseIdentifier = "OrderProductItemCell"
class OrderProductItemView: UICollectionViewController {
var viewModel:
OrderProductsViewModel!
View file.Swift
let headerRefreshTrigger = PublishSubject<Void>()
let retryRefreshTrigger = PublishSubject<Void>()
let refresh = Observable.of(Observable.just(()), headerRefreshTrigger, retryRefreshTrigger.mapToVoid()).merge()
let input = ViewModel.Input(headerRefresh: refresh)
//triggered when retry button tapped
xbutton?.rx.tap.asDriver().drive(onNext: { [weak self] (_) in
self?.retryRefreshTrigger.onNext(())
}).disposed(by: rx.disposeBag)
View config.yml
` version: 2
jobs:
build-and-test:
macos:
xcode: "10.0.0"
working_directory: /Users/distiller/project
environment:
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
FL_OUTPUT_DIR: output
View Carousel.swift
@alouanemed
alouanemed / UICollectionView+flow.swift
Created Nov 27, 2018
UICollectionView spacing margins swift 4
View UICollectionView+flow.swift
/ Create flow layout
let flow = UICollectionViewFlowLayout()
// Define layout constants
let itemSpacing: CGFloat = 1
let minimumCellWidth: CGFloat = 120
let collectionViewWidth = collectionView!.bounds.size.width
// Calculate other required constants
let itemsInOneLine = CGFloat(Int((collectionViewWidth - CGFloat(Int(collectionViewWidth / minimumCellWidth) - 1) * itemSpacing) / minimumCellWidth))
View gist:0bf171ef2782ed97edfb2707fc66a081
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
@alouanemed
alouanemed / GenerateHashkey.kt
Created Oct 22, 2018
generateHashkey Linked In
View GenerateHashkey.kt
fun generateHashkey() {
try {
if (Build.VERSION.SDK_INT >= 28) {
@SuppressLint("WrongConstant") val packageInfo = getPackageManager().getPackageInfo(
getPAckageName(), PackageManager.GET_SIGNING_CERTIFICATES
)
val signatures = packageInfo.signingInfo.getApkContentsSigners()
val md = MessageDigest.getInstance("SHA")
for (signature in signatures) {
View proguard-rules.pro
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose
-dontpreverify
# If you want to enable optimization, remove this for a 1-2% less but longer compile time
#-dontoptimize
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5