Search in sources :

Example 1 with CafeteriaLocalRepository

use of de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository in project TumCampusApp by TCA-Team.

the class DownloadService method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    Utils.log("DownloadService service has started");
    broadcastManager = LocalBroadcastManager.getInstance(this);
    new SyncManager(this);
    CafeteriaRemoteRepository remoteRepository = CafeteriaRemoteRepository.INSTANCE;
    remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(this));
    CafeteriaLocalRepository localRepository = CafeteriaLocalRepository.INSTANCE;
    localRepository.setDb(TcaDb.getInstance(this));
    cafeteriaViewModel = new CafeteriaViewModel(localRepository, remoteRepository, mDisposable);
    // Init sync table
    KinoLocalRepository.INSTANCE.setDb(TcaDb.getInstance(this));
    KinoRemoteRepository.INSTANCE.setTumCabeClient(TUMCabeClient.getInstance(this));
    kinoViewModel = new KinoViewModel(KinoLocalRepository.INSTANCE, KinoRemoteRepository.INSTANCE, mDisposable);
}
Also used : CafeteriaViewModel(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel) SyncManager(de.tum.in.tumcampusapp.utils.sync.SyncManager) KinoViewModel(de.tum.in.tumcampusapp.component.ui.news.KinoViewModel) CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)

Example 2 with CafeteriaLocalRepository

use of de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository in project TumCampusApp by TCA-Team.

the class CafeteriaDetailsSectionFragment method onCreate.

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CafeteriaRemoteRepository remoteRepository = CafeteriaRemoteRepository.INSTANCE;
    remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(getContext()));
    CafeteriaLocalRepository localRepository = CafeteriaLocalRepository.INSTANCE;
    localRepository.setDb(TcaDb.getInstance(getContext()));
    cafeteriaViewModel = new CafeteriaViewModel(localRepository, remoteRepository, mDisposable);
    JodaTimeAndroid.init(getContext());
}
Also used : CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)

Example 3 with CafeteriaLocalRepository

use of de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository in project TumCampusApp by TCA-Team.

the class CafeteriaDetailsSectionsPagerAdapter method setCafeteriaId.

public void setCafeteriaId(Context context, int cafeteriaId) {
    mCafeteriaId = cafeteriaId;
    CafeteriaRemoteRepository remoteRepository = CafeteriaRemoteRepository.INSTANCE;
    remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(context));
    CafeteriaLocalRepository localRepository = CafeteriaLocalRepository.INSTANCE;
    localRepository.setDb(TcaDb.getInstance(context));
    CafeteriaViewModel cafeteriaViewModel = new CafeteriaViewModel(localRepository, remoteRepository, mDisposable);
    cafeteriaViewModel.getAllMenuDates().subscribe(dates -> {
        this.dates = dates;
        this.notifyDataSetChanged();
    });
// Tell we just update the data
}
Also used : CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)

Example 4 with CafeteriaLocalRepository

use of de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository in project TumCampusApp by TCA-Team.

the class MensaWidget method onUpdate.

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    // There may be multiple widgets active, so update all of them
    this.appWidgetManager = appWidgetManager;
    for (int appWidgetId : appWidgetIds) {
        RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.mensa_widget);
        // set the header for the Widget layout
        CafeteriaManager mensaManager = new CafeteriaManager(context);
        CafeteriaLocalRepository localRepository = CafeteriaLocalRepository.INSTANCE;
        localRepository.setDb(TcaDb.getInstance(context));
        Flowable<Cafeteria> cafeteria = localRepository.getCafeteria(mensaManager.getBestMatchMensaId(context));
        cafeteria.map(cafeteria1 -> cafeteria1.getName() + " " + DateUtils.getDateTimeString(new Date())).subscribe(mensaName -> rv.setTextViewText(R.id.mensa_widget_header, mensaName));
        // set the header on click to open the mensa activity
        Intent mensaIntent = new Intent(context, CafeteriaActivity.class);
        mensaIntent.putExtra(Const.CAFETERIA_ID, mensaManager.getBestMatchMensaId(context));
        PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, mensaIntent, 0);
        rv.setOnClickPendingIntent(R.id.mensa_widget_header_container, pendingIntent);
        // set the adapter for the list view in the mensaWidget
        Intent intent = new Intent(context, MensaWidgetService.class);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
        // appWidgetIds[i],
        rv.setRemoteAdapter(R.id.food_item, intent);
        rv.setEmptyView(R.id.empty_view, R.id.empty_view);
        appWidgetManager.updateAppWidget(appWidgetId, rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);
}
Also used : RemoteViews(android.widget.RemoteViews) Context(android.content.Context) R(de.tum.in.tumcampusapp.R) DateUtils(de.tum.in.tumcampusapp.utils.DateUtils) AppWidgetProvider(android.appwidget.AppWidgetProvider) Date(java.util.Date) Uri(android.net.Uri) Const(de.tum.in.tumcampusapp.utils.Const) Intent(android.content.Intent) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) PendingIntent(android.app.PendingIntent) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) AppWidgetManager(android.appwidget.AppWidgetManager) Flowable(io.reactivex.Flowable) CafeteriaActivity(de.tum.in.tumcampusapp.component.ui.cafeteria.activity.CafeteriaActivity) TcaDb(de.tum.in.tumcampusapp.database.TcaDb) MensaWidgetService(de.tum.in.tumcampusapp.service.MensaWidgetService) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) RemoteViews(android.widget.RemoteViews) CafeteriaManager(de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository) Cafeteria(de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria) Date(java.util.Date)

Example 5 with CafeteriaLocalRepository

use of de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository in project TumCampusApp by TCA-Team.

the class CafeteriaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get id from intent if specified
    final Intent intent = getIntent();
    if (intent != null && intent.getExtras() != null && intent.getExtras().containsKey(Const.CAFETERIA_ID)) {
        mCafeteriaId = intent.getExtras().getInt(Const.CAFETERIA_ID);
    }
    mViewPager = findViewById(R.id.pager);
    /*
         *set pagelimit to avoid losing toggle button state.
         *by default it's 1.
         */
    mViewPager.setOffscreenPageLimit(50);
    CafeteriaRemoteRepository remoteRepository = CafeteriaRemoteRepository.INSTANCE;
    remoteRepository.setTumCabeClient(TUMCabeClient.getInstance(this));
    CafeteriaLocalRepository localRepository = CafeteriaLocalRepository.INSTANCE;
    localRepository.setDb(TcaDb.getInstance(this));
    cafeteriaViewModel = new CafeteriaViewModel(localRepository, remoteRepository, mDisposable);
}
Also used : CafeteriaViewModel(de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel) Intent(android.content.Intent) CafeteriaRemoteRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository) CafeteriaLocalRepository(de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)

Aggregations

CafeteriaLocalRepository (de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaLocalRepository)5 CafeteriaRemoteRepository (de.tum.in.tumcampusapp.component.ui.cafeteria.repository.CafeteriaRemoteRepository)4 Intent (android.content.Intent)2 CafeteriaViewModel (de.tum.in.tumcampusapp.component.ui.cafeteria.details.CafeteriaViewModel)2 PendingIntent (android.app.PendingIntent)1 AppWidgetManager (android.appwidget.AppWidgetManager)1 AppWidgetProvider (android.appwidget.AppWidgetProvider)1 Context (android.content.Context)1 Uri (android.net.Uri)1 RemoteViews (android.widget.RemoteViews)1 R (de.tum.in.tumcampusapp.R)1 CafeteriaActivity (de.tum.in.tumcampusapp.component.ui.cafeteria.activity.CafeteriaActivity)1 CafeteriaManager (de.tum.in.tumcampusapp.component.ui.cafeteria.controller.CafeteriaManager)1 Cafeteria (de.tum.in.tumcampusapp.component.ui.cafeteria.model.Cafeteria)1 KinoViewModel (de.tum.in.tumcampusapp.component.ui.news.KinoViewModel)1 TcaDb (de.tum.in.tumcampusapp.database.TcaDb)1 MensaWidgetService (de.tum.in.tumcampusapp.service.MensaWidgetService)1 Const (de.tum.in.tumcampusapp.utils.Const)1 DateUtils (de.tum.in.tumcampusapp.utils.DateUtils)1 SyncManager (de.tum.in.tumcampusapp.utils.sync.SyncManager)1