小编Tun*_*i_D的帖子

Android Room Persistence Library:Upsert

Android的Room持久性库慷慨地包含适用于对象或集合的@Insert和@Update注释.然而,我有一个用例(包含模型的推送通知)需要UPSERT,因为数据可能存在或可能不存在于数据库中.

Sqlite本身没有upsert,并且在这个SO问题中描述了变通方法.鉴于那里的解决方案,如何将它们应用于房间?

更具体地说,如何在Room中实现不会破坏任何外键约束的插入或更新?使用带onConflict = REPLACE的insert将导致onDelete调用该行的任何外键.在我的情况下,onDelete导致级联,重新插入行将导致其他表中的行与外键被删除.这不是预期的行为.

sqlite android android-room android-architecture-components

78
推荐指数
5
解决办法
4万
查看次数

使用CollapsingToolbarLayout的CoordinatorLayout在Dialog片段中使用Keyboard打破

我最近决定将我的应用程序移动到使用新的支持设计库,最近发现了一个非常讨厌的bug.

假设我有一个CoordinatorLayout托管AppBarLayout和任何可滚动的视图,无论是ViewPager,NestedScrollView,还是具有所需滚动行为的RecyclerView; 选择显示一个显示键盘的对话框片段会导致AppBarLayout与滚动视图断开连接,并且它们不再滚动在一起.

此外,滚动视图被强制调整到底部屏幕的一半,而AppBar布局占据了上半部分,尽管它不需要它.

这个bug的视频在这里: Youtube Link

编辑:

将Activity中键盘的softInputMode设置为"adjustPan"可以解决问题.显然,CoordinatorLayout不喜欢通过键盘动态调整大小.

违规的XML看起来像这样,但我有多个XML变体表现出这种行为,其中的共同元素都是他们使用的是CollapsingToolbarLayout:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="192dp"
    android:background="@color/transparent">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="144dp"
        android:elevation="4dp"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginBottom="@dimen/quadruple_margin"
        app:layout_collapseParallaxMultiplier="0.7"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:animateLayoutChanges="true"
            android:background="@color/primary"
            android:orientation="vertical">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="bottom"
                android:adjustViewBounds="true"
                android:scaleType="centerCrop"
                android:src="@drawable/ranking_background" />

            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentTop="true"
                android:layout_gravity="bottom"
                android:background="@color/black_40" />

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/profile_picture"
                android:layout_width="@dimen/double_margin"
                android:layout_height="@dimen/double_margin"
                android:layout_alignBottom="@+id/text"
                android:layout_marginLeft="@dimen/double_margin"
                android:layout_marginStart="@dimen/double_margin"
                android:src="@drawable/image_placeholder"
                android:visibility="gone" />

            <TextView
                android:id="@+id/text"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_alignWithParentIfMissing="true"
                android:layout_marginLeft="@dimen/single_margin"
                android:layout_marginStart="@dimen/single_margin"
                android:layout_marginTop="@dimen/quadruple_margin"
                android:layout_toRightOf="@+id/profile_picture"
                android:text="@string/my_places_for"
                android:textColor="@color/white"
                android:textSize="20sp"
                android:visibility="gone" …
Run Code Online (Sandbox Code Playgroud)

android android-keypad android-dialogfragment android-support-library android-coordinatorlayout

15
推荐指数
2
解决办法
6758
查看次数

ViewHolder中的嵌套RecyclerView会破坏折叠工具栏布局

我有一个在CoordinatorLayout中托管的垂直RecyclerView,具有折叠工具栏布局.此RecyclerView的ViewHolder包含另一个带有GridLayoutManager的RecyclerView.

这种嵌套的原因是内部RecyclerView显示的图片集合可以包含1-20张图片.我不知道会有多少张图片,但Grid的跨度必须始终为3.每次绑定ViewHolder时,我都会调整RecyclerView的布局参数以容纳内容.

如果没有CollapsingToolBarLayout,这很有效.但是,如果有一个折叠的工具栏,用我的手指在内部RecyclerView上滚动不会滚动折叠工具栏,但滚动另一个项目却会.

要重新强调,在绑定的ViewHolder中,如果我开始滚动除嵌套的RecyclerView之外的任何其他项目,滚动工作正常.但是,如果我在嵌套的RecyclerView上开始滚动,那么它会中断.

是否可以阻止内部RecyclerView上的滚动拦截,只允许父滚动?我希望内部的RecyclerView仍能处理点击.

以下是该现象的YouTube链接:https://youtu.be/fzj7HmqskzU

以下是父RecyclerView的XML:

<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"
tools:context=".MainActivityFragment">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="4dp"
        app:contentScrim="?attr/colorPrimary"
        app:layout_collapseParallaxMultiplier="0.7"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <View
            android:id="@+id/header_view"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            android:animateLayoutChanges="true"
            android:background="@color/primary" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_bar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:elevation="4dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/Theme.AppCompat.NoActionBar"
            app:theme="@style/Theme.AppCompat.NoActionBar" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

这是托管嵌套RecyclerView的主要ViewHolder:

public class SimpleAdapter extends RecyclerView.Adapter<SimpleAdapter.ViewHolder> {

private static final int MODEL_OBJECT = 1;

private List<ModelObject> modelObjects;

private Context context;

private int imageSize;

public SimpleAdapter(List<ModelObject> modelObjects) …
Run Code Online (Sandbox Code Playgroud)

android-recyclerview androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout

8
推荐指数
2
解决办法
2619
查看次数

在Google App Engine上连接Mongoose

我已成功在Google App引擎引擎上部署了自定义Node.js应用程序.但是我在启动应用程序时遇到问题,因为尝试连接时mongoose超时.令人沮丧的是,猫鼬在我的本地机器上与完全相同的参数连接得很好.

我的MongoDb URI的形式如下:

 mongodb://<dbuser>:<dbpassword>@xxxx.mlab.com:<portNumber>/d??b-name
Run Code Online (Sandbox Code Playgroud)

正如URI所暗示的那样,db由mlab托管.它是Google Cloud Platform上的沙箱实例.但是我没有使用Google Compute Engine部署数据库.在mlab上完成设置过程时,我只是选择在GCP上主持.

我在SO上遇到过类似的问题,但大多数都没有接受.只是在评论中不同的话语,没有公认的解决方案.

因此,我的问题是,在尝试连接上述URI时,我的App Engine实例与本地计算机有何不同?我选择让mlab在GCP上托管它的事实是什么?如果我选择在亚马逊AWS上托管它会有什么不同吗?问题的根本原因究竟是什么?

作为参考,以下是我发现的类似问题:

另外,如果有帮助,MongoDB是作为分贝的商业模式中,数据存储的应用程序的快速会话,并从socket.io存储临时数据.

部署后从App Engine发生错误堆栈跟踪:

2017-10-18 02:13:46 default[20171017t215757]  npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
2017-10-18 02:13:46 default[20171017t215757]  npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
2017-10-18 02:13:46 default[20171017t215757]  npm ERR! enoent This is most likely not a problem with npm itself
2017-10-18 02:13:46 default[20171017t215757]  npm ERR! enoent and is related to npm not being able to find …
Run Code Online (Sandbox Code Playgroud)

google-app-engine mongoose mongodb node.js google-compute-engine

6
推荐指数
2
解决办法
1637
查看次数

Android Oreo:通知通道的分组通知

我按照此处提供的文档进行操作,可以在Android N及更高版本上成功创建通知组.然而,我遇到的问题是Android Oreo,发布到群组的每个通知都会为群组播放声音.

这很烦人,因为我只想播放一次声音.每个单独的通知都是用户没有为他们所在的每个聊天室阅读的聊天内容的摘要.当有多个聊天室有未读消息时,我需要进行分组.

似乎没有办法动态地为通知设置声音,它仅限于创建频道.

我尝试了Dan Lew 在这里建议的内容,但仍然会为每个通知播放通知声音.

因此,我的问题是,如何在Android Oreo中获得分组通知,而不是每个都有通知声音播放?

android android-notifications android-8.0-oreo

5
推荐指数
1
解决办法
1668
查看次数