Skip to content

Instantly share code, notes, and snippets.

View alouanemed's full-sized avatar
:octocat:
FOCUS

Mohamed Alouane alouanemed

:octocat:
FOCUS
View GitHub Profile
@alouanemed
alouanemed / viewModel.swift
Created September 6, 2020 11:20
retreive post fav reactions with rxswift
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)
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
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
private let reuseIdentifier = "OrderProductItemCell"
class OrderProductItemView: UICollectionViewController {
var viewModel:
OrderProductsViewModel!
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)
` 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
@alouanemed
alouanemed / UICollectionView+flow.swift
Created November 27, 2018 12:41
UICollectionView spacing margins swift 4
/ 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))
<?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 October 22, 2018 12:58
generateHashkey Linked In
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) {
-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